Struct scfg::Scfg

source ·
pub struct Scfg { /* private fields */ }
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§

source§

impl Scfg

source

pub fn new() -> Self

Creates a new empty document

source

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

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.

source

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

Retrieves the all directives with a particular name.

source

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

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

source

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

Does the document contain a directive with name.

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

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

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.

source

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

Removes all directives with the supplied name, returning them.

source

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

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

source

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

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§

source§

impl Clone for Scfg

source§

fn clone(&self) -> Scfg

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Scfg

source§

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

Formats the value using the given formatter. Read more
source§

impl Default for Scfg

source§

fn default() -> Scfg

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

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

source§

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

Creates a value from an iterator. Read more
source§

impl FromStr for Scfg

source§

type Err = Error

The associated error which can be returned from parsing.
source§

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

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

impl PartialEq for Scfg

source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Scfg

source§

impl StructuralPartialEq for Scfg

Auto Trait Implementations§

§

impl Freeze for Scfg

§

impl RefUnwindSafe for Scfg

§

impl Send for Scfg

§

impl Sync for Scfg

§

impl Unpin for Scfg

§

impl UnwindSafe for Scfg

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> CloneToUninit for T
where T: Clone,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. 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> ToOwned for T
where T: Clone,

source§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.