pub struct ObjectPath(/* private fields */);
Expand description
This represents a object path.
Implementations§
Source§impl ObjectPath
impl ObjectPath
Sourcepub fn append(&mut self, element: &str) -> bool
pub fn append(&mut self, element: &str) -> bool
Append an element to the object path.
Returns true
if the new element could be appended, otherwise false
.
An element cannot be appended if the element contain a character, which is not allowed.
§Example
let mut object_path = ObjectPath::try_from("/object").unwrap();
assert!(object_path.append("path"));
assert!(!object_path.append("/path"));
assert_eq!(&object_path, "/object/path");
Sourcepub fn starts_with(&self, base: &ObjectPath) -> bool
pub fn starts_with(&self, base: &ObjectPath) -> bool
Determines whether base
is a prefix of self
.
§Example
let base = ObjectPath::try_from("/object").unwrap();
let path_1 = ObjectPath::try_from("/object/path").unwrap();
let path_2 = ObjectPath::try_from("/object_/path").unwrap();
assert!(path_1.starts_with(&base));
assert!(!path_2.starts_with(&base));
assert!(!base.starts_with(&base));
Sourcepub fn strip_prefix_elements<'a, 'b>(
&'a self,
base: &'b ObjectPath,
) -> Option<Split<'a, char>>
pub fn strip_prefix_elements<'a, 'b>( &'a self, base: &'b ObjectPath, ) -> Option<Split<'a, char>>
Returns a Split
object with the prefix removed.
§Example
let base = ObjectPath::try_from("/object").unwrap();
let path_1 = ObjectPath::try_from("/object/path").unwrap();
let path_2 = ObjectPath::try_from("/object_/path").unwrap();
let path_3 = ObjectPath::try_from("/object/path/element").unwrap();
let path_1_base_vec: Vec<&str> = path_1.strip_prefix_elements(&base).unwrap().collect();
let path_3_base_vec: Vec<&str> = path_3.strip_prefix_elements(&base).unwrap().collect();
assert_eq!(path_1_base_vec, vec!["path"]);
assert!(path_2.strip_prefix_elements(&base).is_none());
assert_eq!(path_3_base_vec, vec!["path", "element"]);
assert!(base.strip_prefix_elements(&base).is_none());
Trait Implementations§
Source§impl AsRef<str> for ObjectPath
impl AsRef<str> for ObjectPath
Source§impl Clone for ObjectPath
impl Clone for ObjectPath
Source§fn clone(&self) -> ObjectPath
fn clone(&self) -> ObjectPath
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for ObjectPath
impl Debug for ObjectPath
Source§impl Default for ObjectPath
impl Default for ObjectPath
Source§impl Display for ObjectPath
impl Display for ObjectPath
Source§impl From<ObjectPath> for String
impl From<ObjectPath> for String
Source§fn from(object_path: ObjectPath) -> Self
fn from(object_path: ObjectPath) -> Self
Converts to this type from the input type.
Source§impl Hash for ObjectPath
impl Hash for ObjectPath
Source§impl Ord for ObjectPath
impl Ord for ObjectPath
Source§fn cmp(&self, other: &ObjectPath) -> Ordering
fn cmp(&self, other: &ObjectPath) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq<str> for ObjectPath
impl PartialEq<str> for ObjectPath
Source§impl PartialEq for ObjectPath
impl PartialEq for ObjectPath
Source§impl PartialOrd for ObjectPath
impl PartialOrd for ObjectPath
Source§impl TryFrom<&[u8]> for ObjectPath
impl TryFrom<&[u8]> for ObjectPath
Source§impl TryFrom<&str> for ObjectPath
impl TryFrom<&str> for ObjectPath
Source§impl TryFrom<String> for ObjectPath
impl TryFrom<String> for ObjectPath
impl Eq for ObjectPath
impl StructuralPartialEq for ObjectPath
Auto Trait Implementations§
impl Freeze for ObjectPath
impl RefUnwindSafe for ObjectPath
impl Send for ObjectPath
impl Sync for ObjectPath
impl Unpin for ObjectPath
impl UnwindSafe for ObjectPath
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