Struct scfg::Scfg[][src]

pub struct Scfg { /* fields omitted */ }
Expand description

An scfg document. Implemented as a multimap.

If the preserve_order feature is enabled, the directive names will be kept in the order of their first appearance. Otherwise, they will be sorted by name.

Implementations

impl Scfg[src]

pub fn new() -> Self[src]

Creates a new empty document

pub fn get<Q: ?Sized>(&self, name: &Q) -> Option<&Directive> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash
[src]

Retrieves the first directive with a particular name.

This will return None if either, the name is not found, or if the name somehow has no directives.

pub fn get_all<Q: ?Sized>(&self, name: &Q) -> Option<&[Directive]> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash
[src]

Retrieves the all directives with a particular name.

pub fn get_all_mut<Q: ?Sized>(
    &mut self,
    name: &Q
) -> Option<&mut Vec<Directive>> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash
[src]

Retrieves a mutable reference to all directives with a particular name.

pub fn contains<Q: ?Sized>(&self, name: &Q) -> bool where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash
[src]

Does the document contain a directive with name.

let mut scfg = Scfg::new();
scfg.add("foo");
assert!(scfg.contains("foo"));
assert!(!scfg.contains("bar"));

pub fn add(&mut self, name: impl Into<String>) -> &mut Directive[src]

Adds a new name returning the new (empty) directive.

let mut scfg = Scfg::new();
let dir = scfg.add("dir1");
assert_eq!(*dir, Directive::default());

Note

This does not validate that name is a legal scfg word. It is possible to create unparsable documents should name contain control characters or newlines.

pub fn remove<Q: ?Sized>(&mut self, name: &Q) -> Option<Vec<Directive>> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash
[src]

Removes all directives with the supplied name, returning them.

pub fn remove_entry<Q: ?Sized>(
    &mut self,
    name: &Q
) -> Option<(String, Vec<Directive>)> where
    String: Borrow<Q>,
    Q: Ord + Eq + Hash
[src]

Removes all directives with the supplied name, returning them, and their key.

pub fn write<W>(&self, writer: &mut W) -> Result<()> where
    W: Write
[src]

Writes the document to the specified writer. If efficiency is a concern, it may be best to wrap the writer in a BufWriter first. This will not write any comments that the document had if it was parsed first.

Trait Implementations

impl Clone for Scfg[src]

fn clone(&self) -> Scfg[src]

Returns a copy of the value. Read more

fn clone_from(&mut self, source: &Self)1.0.0[src]

Performs copy-assignment from source. Read more

impl Debug for Scfg[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

impl Default for Scfg[src]

fn default() -> Scfg[src]

Returns the “default value” for a type. Read more

impl<K: Into<String>> FromIterator<(K, Directive)> for Scfg[src]

fn from_iter<T>(it: T) -> Self where
    T: IntoIterator<Item = (K, Directive)>, 
[src]

Creates a value from an iterator. Read more

impl FromStr for Scfg[src]

type Err = ParseError

The associated error which can be returned from parsing.

fn from_str(src: &str) -> Result<Self, Self::Err>[src]

Parses a string s to return a value of this type. Read more

impl PartialEq<Scfg> for Scfg[src]

fn eq(&self, other: &Scfg) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &Scfg) -> bool[src]

This method tests for !=.

impl Eq for Scfg[src]

impl StructuralEq for Scfg[src]

impl StructuralPartialEq for Scfg[src]

Auto Trait Implementations

impl RefUnwindSafe for Scfg

impl Send for Scfg

impl Sync for Scfg

impl Unpin for Scfg

impl UnwindSafe for Scfg

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more

impl<T> From<T> for T[src]

pub fn from(t: T) -> T[src]

Performs the conversion.

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

pub fn into(self) -> U[src]

Performs the conversion.

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

pub fn to_owned(&self) -> T[src]

Creates owned data from borrowed data, usually by cloning. Read more

pub fn clone_into(&self, target: &mut T)[src]

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

Performs the conversion.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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

Performs the conversion.