pub struct ConfigKey(/* private fields */);
Expand description
Represents a configuration key. Configuration keys are case-insensitive, and all instances are lower-cased.
Implementations§
Source§impl ConfigKey
impl ConfigKey
pub fn is_empty(&self) -> bool
Sourcepub fn section_key(&self) -> Self
pub fn section_key(&self) -> Self
Get the section key given a config path.
§Arguments
path
- configuration path.
§Example
use preftool::ConfigKey;
assert_eq!(ConfigKey::from("").section_key(), "");
assert_eq!(ConfigKey::from("foo").section_key(), "foo");
assert_eq!(ConfigKey::from("foo:bar").section_key(), "bar");
assert_eq!(ConfigKey::from("foo:bar:baz").section_key(), "baz");
Sourcepub fn parent(&self) -> Self
pub fn parent(&self) -> Self
Get the parent config path.
§Arguments
path
- configuration path.
§Example
use preftool::ConfigKey;
assert_eq!(ConfigKey::from("").parent(), "");
assert_eq!(ConfigKey::from("foo").parent(), "");
assert_eq!(ConfigKey::from("foo:bar").parent(), "foo");
assert_eq!(ConfigKey::from("foo:bar:baz").parent(), "foo:bar");
Sourcepub fn combine<S2: Into<ConfigKey>>(&self, key: S2) -> Self
pub fn combine<S2: Into<ConfigKey>>(&self, key: S2) -> Self
Combine two config path segments.
§Arguments
path
- configuration path.key
- configuration sub-key.
§Example
use preftool::ConfigKey;
assert_eq!(ConfigKey::from("").combine(""), "");
assert_eq!(ConfigKey::from("").combine("foo"), "foo");
assert_eq!(ConfigKey::from("foo:bar").combine("baz"), "foo:bar:baz");
assert_eq!(ConfigKey::from("foo").combine("bar:baz"), "foo:bar:baz");
Sourcepub fn join<S: Into<ConfigKey>, I: IntoIterator<Item = S>>(parts: I) -> Self
pub fn join<S: Into<ConfigKey>, I: IntoIterator<Item = S>>(parts: I) -> Self
Join a list of path segments into one config path.
§Arguments
paths
- configuration path segments.
§Example
use preftool::ConfigKey;
assert_eq!(ConfigKey::join::<&'static str, Vec<_>>(vec!()), "");
assert_eq!(ConfigKey::join(vec!("foo")), "foo");
assert_eq!(ConfigKey::join(vec!("", "foo", "")), "foo");
assert_eq!(ConfigKey::join(vec!("", "foo:bar", "", "baz")), "foo:bar:baz");
Sourcepub fn unsafe_from<S: Into<String>>(value: S) -> Self
pub fn unsafe_from<S: Into<String>>(value: S) -> Self
Construct a config key from a string. This does not do any
validation/lowercasing of the string, and should only be used
if the string is guaranteed to be safe. This method is typically
used by derive
implementations.
§Arguments
- value - string value.
§Example
use preftool::ConfigKey;
assert_eq!(ConfigKey::unsafe_from("foo:bar"), "foo:bar");
Trait Implementations§
impl Eq for ConfigKey
Auto Trait Implementations§
impl Freeze for ConfigKey
impl RefUnwindSafe for ConfigKey
impl Send for ConfigKey
impl Sync for ConfigKey
impl Unpin for ConfigKey
impl UnwindSafe for ConfigKey
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
Mutably borrows from an owned value. Read more