keydata

Struct Section

Source
pub struct Section {
    pub name: String,
    pub data: HashMap<String, String>,
}
Expand description

A Section to hold keynote file entries (key-value pairs)

Fields§

§name: String

name of the Section

§data: HashMap<String, String>

hashmap to hold key value pairs that make up entries

Implementations§

Source§

impl Section

Source

pub fn new(name: &str) -> Section

Returns a Section with the name given

§Arguments
  • name - section name as string slice
§Examples ///
use keydata::Section; 
let s = Section::new("test_section");
assert_eq!(s.name, "test_section");
assert_eq!(s.data.len(), 0);
Source

pub fn build_section_string(section_name: &str) -> String

Formats a string into the form it appears as in the data file

§Arguments
  • section_name - name of section to format as string slice
§Examples ///
use keydata::Section; 
let s = Section::build_section_string("test_section");
assert_eq!(s, "<test_section>\n"); 
Source

pub fn get_section_name_from_string(line: &str) -> Option<&str>

Returns name of a section from formatted section string. None if line is not valid section string;

§Arguments
  • line - string slice containing section string
§Examples ///
use keydata::Section; 
let line = "<test_section>\n";
let sn = Section::get_section_name_from_string(line);
assert!(sn.is_some());
assert_eq!(sn.unwrap(), "test_section"); 
Source

pub fn add_entry(&mut self, key: &str, value: &str)

Adds a key-value pair entry to the Sections data

§Arguments
  • key - entry key as string slice
  • value - entry value as string slice
§Examples ///
use keydata::Section; 
let mut s = Section::new("test_section");
assert_eq!(s.data.len(), 0);
 
s.add_entry("theKey", "theValue");
assert_eq!(s.data.len(), 1);
assert_eq!(s.data.get("theKey").unwrap(), "theValue"); 

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.