pub struct CfgPathResolver { /* private fields */ }
Expand description
A variable resolver for paths in a configuration file.
Typically there should be one resolver per application, and the application should share the
resolver throughout the application to have consistent path variable expansions. Typically the
application would create its own resolver with its application-specific variables, but note that
TorClientConfig
is an exception which does not accept a resolver from the application and
instead generates its own. This is done for backwards compatibility reasons.
Once constructed, they are used during calls to CfgPath::path
to expand variables in the
path.
Implementations§
Source§impl CfgPathResolver
impl CfgPathResolver
Sourcepub fn set_var(
&mut self,
var: impl Into<String>,
val: Result<Cow<'static, Path>, CfgPathError>,
)
pub fn set_var( &mut self, var: impl Into<String>, val: Result<Cow<'static, Path>, CfgPathError>, )
Set a variable var
that will be replaced with val
when a CfgPath
is expanded.
Setting an Err
is useful when a variable is supported, but for whatever reason it can’t be
expanded, and you’d like to return a more-specific error. An example might be a USER_HOME
variable for a user that doesn’t have a HOME
environment variable set.
use std::path::Path;
use tor_config_path::{CfgPath, CfgPathResolver};
let mut path_resolver = CfgPathResolver::default();
path_resolver.set_var("FOO", Ok(Path::new("/foo").to_owned().into()));
let path = CfgPath::new("${FOO}/bar".into());
#[cfg(feature = "expand-paths")]
assert_eq!(path.path(&path_resolver).unwrap(), Path::new("/foo/bar"));
#[cfg(not(feature = "expand-paths"))]
assert!(path.path(&path_resolver).is_err());
Trait Implementations§
Source§impl Clone for CfgPathResolver
impl Clone for CfgPathResolver
Source§fn clone(&self) -> CfgPathResolver
fn clone(&self) -> CfgPathResolver
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for CfgPathResolver
impl Debug for CfgPathResolver
Source§impl Default for CfgPathResolver
impl Default for CfgPathResolver
Source§fn default() -> CfgPathResolver
fn default() -> CfgPathResolver
Auto Trait Implementations§
impl Freeze for CfgPathResolver
impl RefUnwindSafe for CfgPathResolver
impl Send for CfgPathResolver
impl Sync for CfgPathResolver
impl Unpin for CfgPathResolver
impl UnwindSafe for CfgPathResolver
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 48 bytes