[][src]Struct scfg::Scfg

pub struct Scfg { /* fields omitted */ }

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]

impl Debug for Scfg[src]

impl Default for Scfg[src]

impl Eq for Scfg[src]

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

impl FromStr for Scfg[src]

type Err = ParseError

The associated error which can be returned from parsing.

impl PartialEq<Scfg> 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]

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

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

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

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

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

type Owned = T

The resulting type after obtaining ownership.

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.

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.