Trait miniconf::Miniconf

source ·
pub trait Miniconf {
    // Required methods
    fn set_path<'a, P: Peekable<Item = &'a str>>(
        &mut self,
        path_parts: &'a mut P,
        value: &[u8]
    ) -> Result<usize, Error>;
    fn get_path<'a, P: Peekable<Item = &'a str>>(
        &self,
        path_parts: &'a mut P,
        value: &mut [u8]
    ) -> Result<usize, Error>;
    fn next_path<const TS: usize>(
        state: &mut [usize],
        path: &mut String<TS>
    ) -> Result<bool, IterError>;
    fn metadata() -> Metadata;

    // Provided methods
    fn set(&mut self, path: &str, data: &[u8]) -> Result<usize, Error> { ... }
    fn get(&self, path: &str, data: &mut [u8]) -> Result<usize, Error> { ... }
    fn iter_paths<const L: usize, const TS: usize>(
        
    ) -> Result<MiniconfIter<Self, L, TS>, IterError> { ... }
    fn unchecked_iter_paths<const L: usize, const TS: usize>(
        count: Option<usize>
    ) -> MiniconfIter<Self, L, TS>  { ... }
}
Expand description

Trait exposing serialization/deserialization of elements by path.

Required Methods§

source

fn set_path<'a, P: Peekable<Item = &'a str>>( &mut self, path_parts: &'a mut P, value: &[u8] ) -> Result<usize, Error>

Deserialize an element by path.

Args
  • path_parts: A Peekable Iterator identifying the element.
  • value: A slice containing the data to be deserialized.
Returns

The number of bytes consumed from value or an Error.

source

fn get_path<'a, P: Peekable<Item = &'a str>>( &self, path_parts: &'a mut P, value: &mut [u8] ) -> Result<usize, Error>

Serialize an element by path.

Args
  • path_parts: A Peekable Iterator identifying the element.
  • value: A slice for the value to be serialized into.
Returns

The number of bytes written to value or an Error.

source

fn next_path<const TS: usize>( state: &mut [usize], path: &mut String<TS> ) -> Result<bool, IterError>

Get the next path in the namespace.

This is usually not called directly but through a MiniconfIter returned by Miniconf::iter_paths.

Args
  • state: A state array indicating the path to be retrieved. A zeroed vector indicates the first path. The vector is advanced such that the next element will be retrieved when called again. The array needs to be at least as long as the maximum path depth.
  • path: A string to write the path into.
Returns

A bool indicating a valid path was written to path from the given state. If false, path is invalid and there are no more paths within self at and beyond state. May return IterError indicating insufficient state or path size.

source

fn metadata() -> Metadata

Get metadata about the paths in the namespace.

Provided Methods§

source

fn set(&mut self, path: &str, data: &[u8]) -> Result<usize, Error>

Update an element by path.

Args
  • path - The path to the element with ‘/’ as the separator.
  • data - The serialized data making up the content.
Returns

The number of bytes consumed from data or an Error.

source

fn get(&self, path: &str, data: &mut [u8]) -> Result<usize, Error>

Retrieve a serialized value by path.

Args
  • path - The path to the element with ‘/’ as the separator.
  • data - The buffer to serialize the data into.
Returns

The number of bytes used in the data buffer or an Error.

source

fn iter_paths<const L: usize, const TS: usize>( ) -> Result<MiniconfIter<Self, L, TS>, IterError>

Create an iterator of all possible paths.

This is a depth-first walk. The iterator will walk all paths, even those that may be absent at run-time (see Option). The iterator has an exact and trusted Iterator::size_hint.

Template Arguments
  • L - The maximum depth of the path, i.e. number of separators plus 1.
  • TS - The maximum length of the path in bytes.
Returns

A MiniconfIter of paths or an IterError if L or TS are insufficient.

source

fn unchecked_iter_paths<const L: usize, const TS: usize>( count: Option<usize> ) -> MiniconfIter<Self, L, TS>

Create an iterator of all possible paths.

This is a depth-first walk. It will return all paths, even those that may be absent at run-time.

Note

This does not check that the path size or state vector are large enough. If they are not, panics may be generated internally by the library.

Args
  • count: Optional iterator length if known.
Template Arguments
  • L - The maximum depth of the path, i.e. number of separators plus 1.
  • TS - The maximum length of the path in bytes.

Implementations on Foreign Types§

source§

impl<T: Serialize + DeserializeOwned, const N: usize> Miniconf for [T; N]

source§

fn set_path<'a, P: Peekable<Item = &'a str>>( &mut self, path_parts: &mut P, value: &[u8] ) -> Result<usize, Error>

source§

fn get_path<'a, P: Peekable<Item = &'a str>>( &self, path_parts: &mut P, value: &mut [u8] ) -> Result<usize, Error>

source§

fn metadata() -> Metadata

source§

fn next_path<const TS: usize>( state: &mut [usize], path: &mut String<TS> ) -> Result<bool, IterError>

source§

impl<T: Serialize + DeserializeOwned> Miniconf for Option<T>

source§

fn set_path<'a, P: Peekable<Item = &'a str>>( &mut self, path_parts: &mut P, value: &[u8] ) -> Result<usize, Error>

source§

fn get_path<'a, P: Peekable<Item = &'a str>>( &self, path_parts: &mut P, value: &mut [u8] ) -> Result<usize, Error>

source§

fn metadata() -> Metadata

source§

fn next_path<const TS: usize>( state: &mut [usize], path: &mut String<TS> ) -> Result<bool, IterError>

Implementors§

source§

impl<T: Miniconf> Miniconf for miniconf::Option<T>

source§

impl<T: Miniconf, const N: usize> Miniconf for Array<T, N>