Resolver

Struct Resolver 

Source
pub struct Resolver { /* private fields */ }
Expand description

An inventory of group sources used to resolve group names to node sets

The FromStr implementation of NodeSet uses the global resolver which can be setup to read group sources from the default configuration file as follows:

use nodeset::{NodeSet, Resolver};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    Resolver::set_global(Resolver::from_config()?).unwrap();

    let ns: NodeSet = "@group".parse()?;

    Ok(())
}

Implementations§

Source§

impl Resolver

Source

pub fn from_config() -> Result<Self, ConfigurationError>

Create a new resolver from the default configuration files

Source

pub fn set_global(resolver: Resolver) -> Result<(), Resolver>

Set the global resolver to use for parsing NodeSet using the FromStr trait

Returns an error if the global resolver is already set

Source

pub fn get_global() -> &'static Resolver

Get the global resolver

Source

pub fn resolve<T: IdRange + PartialEq + Clone + Display + Debug>( &self, source: Option<&str>, group: &str, ) -> Result<NodeSet<T>, NodeSetParseError>

Resolve a group name to a NodeSet

If source is None, the default group source of the resolver is used.

Source

pub fn list_groups<T: IdRange + PartialEq + Clone + Display + Debug>( &self, source: Option<&str>, ) -> NodeSet<T>

List groups from a source

If source is None, the default group source of the resolver is used.

Source

pub fn list_all_groups<T: IdRange + PartialEq + Clone + Display + Debug>( &self, ) -> impl Iterator<Item = (&str, NodeSet<T>)>

List groups from all sources

Returns a list of tuples with the source name and the group name

Source

pub fn sources(&self) -> impl Iterator<Item = &String>

List all sources

Source

pub fn default_source(&self) -> &str

Returns the default group source for this resolver

Trait Implementations§

Source§

impl Debug for Resolver

Source§

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

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

impl Default for Resolver

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. 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.