[−][src]Struct def::Describer
Describer holds descriptions of files and directories.
Types of Descriptions
- Specific description: A string mapped to a path describing a file or directory. When describe is called this will be retrieved as is.
- Pattern description: A string mapped to a directory's path describing a child of the directory. When description of a child is wanted, the pattern is retrieved. In patterns, a wildcard is interpreted as a place holder for child's name, and are replaced by the name when retreived.
If a string can be described using both a pattern and a specific description, the specific description will be favoured.
Examples
// Create a mutable describer. let mut describer = def::Describer::new(); // Map a description to a given path. describer.add_description("path/to/directory", "This is an empty directory."); // Map a pattern to a given path. The pattern applies to the path's // children. "*" works as a placeholder and will be replaced by the // child's name. describer.add_pattern("parent/directory", "* is a child of parent/directory."); // The description is retrieved as is. assert_eq!( describer.describe("path/to/directory"), Some("This is an empty directory.".to_string()) ); // "*" is replaced with "test". assert_eq!( describer.describe("parent/directory/test"), Some("test is a child of parent/directory.".to_string()) ); // Despite having a pattern mapped to it, the pattern only applies to // its children. assert_eq!(describer.describe("parent/directory"), None);
Implementations
impl Describer
[src]
pub fn new() -> Describer
[src]
Create and return a new empty describer.
pub fn new_with(
d: HashMap<String, String>,
p: HashMap<String, String>
) -> Describer
[src]
d: HashMap<String, String>,
p: HashMap<String, String>
) -> Describer
Create and return a new describer using given HashMaps.
Arguments
d
- A map of descriptions.p
- A map of patterns.
pub fn new_from_json(json: &str) -> Result<Describer, Error>
[src]
Create and return a new describer using the given JSON value.
Arguments
json
- A string representing a JSON value that can be deserialized into a Describer. An error is returned if the JSON string can't be deserialized.
pub fn describe(&self, path: &str) -> Option<String>
[src]
Return a description of the given path or None if no description exists. The descriptions map is checked for a description first, if none is found, then the patterns map is checked.
pub fn add_description(&mut self, path: &str, desc: &str)
[src]
Add a description to the descriptions map.
pub fn add_pattern(&mut self, path: &str, desc: &str)
[src]
Add a pattern to the patterns map.
pub fn to_json(&self, pretty: bool) -> Result<String, Error>
[src]
Return a string JSON representation of this Describer. This is subsequently written to a file to be re-loaded on next run.
Arguments
pretty
- If true, return a "pretty" JSON string.
Trait Implementations
impl Debug for Describer
[src]
impl Default for Describer
[src]
impl<'de> Deserialize<'de> for Describer
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
impl Serialize for Describer
[src]
Auto Trait Implementations
impl RefUnwindSafe for Describer
impl Send for Describer
impl Sync for Describer
impl Unpin for Describer
impl UnwindSafe for Describer
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> DeserializeOwned for T where
T: for<'de> Deserialize<'de>,
[src]
T: for<'de> Deserialize<'de>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,