Struct async_rustbus::rustbus_core::path::ObjectPathBuf [−][src]
pub struct ObjectPathBuf { /* fields omitted */ }
Implementations
An owned, mutable Dbus object path akin to String
or std::path::PathBuf
.
push
, pop
and others can be used used to modify the ObjectPathBuf
in-place.
ObjectPathBuf
implements Deref
to ObjectPath
allowing for all methods on ObjectPath
to be used on ObjectPathBuf
.
Notes
-
ObjectPathBuf
is stored as a wrapper aroundOption<PathBuf>
, where theNone
case is equivelent to a root path. -
As a result of the above point, root paths (a single
/
seperator) are special case that does not result in a heap allocation. This means thatnew
does not result in an allocation on its own.
Create a new root path consisting of a single /
seperator.
The ObjectPathBuf
returned by this method does not result in an allocation until it is modified.
Create a new root path and preallocate space on the heap for additions to the path.
If the size of the object path is known ahead time, this method can provide a performance benefit by avoid multiple reallocations.
When capacity
is zero this method is equivelent to new
.
Coerces to a ObjectPath
slice.
Truncates the object path into a root path.
This does not affect the capacity of the ObjectPathBuf
.
Append an ObjectPath
to this one.
Append a Path
to this one.
If path
is invalid this method panics.
If it is unknown if path
is valid use [push_path_checked
] instead.
Panics
path
must be a valid object path with two exceptions:
path
can be relative or empty.
If the above conditions are not met this function will panic.
Examples
use std::convert::TryFrom; use async_rustbus::rustbus_core::path::{ObjectPath, ObjectPathBuf}; let target = ObjectPath::from_str("/example/path/to_append").unwrap(); let mut opb0 = ObjectPathBuf::try_from("/example").unwrap(); let mut opb1 = opb0.clone(); opb0.push_path("/path/to_append"); opb1.push_path("path/to_append"); assert_eq!(&opb0, target); assert_eq!(&opb1, target);
These should panic for different reasons.
use std::convert::TryFrom; use async_rustbus::rustbus_core::path::{ObjectPath, ObjectPathBuf}; let target = ObjectPath::from_str("/example/path/to_append").unwrap(); let mut original = ObjectPathBuf::try_from("/example").unwrap(); // Each line panics for different reasons original.push_path("/path//consecutive/slash"); original.push_path("/p@th");
Check and append path
to the ObjectPathBuf
if it is valid.
path
must be a valid DBus object path with two exceptions:
path
can be relative or empty.
If these conditions are not met then an Err
is returned.
Examples
use std::convert::TryFrom; use async_rustbus::rustbus_core::path::{ObjectPath, ObjectPathBuf}; let target = ObjectPath::from_str("/example/path/to_append").unwrap(); let mut opb0 = ObjectPathBuf::try_from("/example").unwrap(); let mut opb1 = opb0.clone(); opb0.push_path_checked("/path/to_append").unwrap(); opb1.push_path_checked("path/to_append").unwrap(); assert_eq!(&opb0, target); assert_eq!(&opb1, target); opb0.push_path_checked("/path//consecutive/slash").unwrap_err(); opb1.push_path_checked("/p@th").unwrap_err();
Truncate the ObjectPathBuf
to parent
.
Returns true if the path changed.
Methods from Deref<Target = ObjectPath>
Get the ObjectPath
as a &str
.
Unlike ordinary std::path::Path
, ObjectPath
s are always valid Rust str
s making this possible.
pub fn strip_prefix<P: AsRef<Path> + ?Sized>(
&self,
p: &P
) -> Result<&ObjectPath, StripPrefixError>
pub fn strip_prefix<P: AsRef<Path> + ?Sized>(
&self,
p: &P
) -> Result<&ObjectPath, StripPrefixError>
Strip the prefix of the ObjectPath
.
Unlike Path::strip_prefix
this method will always leave the path will always remain absolute.
Examples
use async_rustbus::rustbus_core::path::ObjectPath; let original = ObjectPath::from_str("/example/path/to_strip").unwrap(); let target = ObjectPath::from_str("/path/to_strip").unwrap(); /* These two lines are equivelent because paths must always remain absolute, so the root '/' is readded in the second example. Note the second line is not a valid ObjectPath */ let stripped0 = original.strip_prefix("/example").unwrap(); let stripped1 = original.strip_prefix("/example/").unwrap(); assert_eq!(stripped0, target); assert_eq!(stripped1, target); original.strip_prefix("/example/other").unwrap_err(); original.strip_prefix("/example/pa").unwrap_err(); // Because the only thing stripped is the root sep this does nothing as it gets readded. let stripped2 = original.strip_prefix("/").unwrap(); assert_eq!(stripped2, original); let stripped3 = original.strip_prefix(original).unwrap(); assert_eq!(stripped3, ObjectPath::root_path());
Get the parent of the ObjectPath
by removing the last element.
If the ObjectPath
is a root path then None
is returned.
Retrieves the last element of the ObjectPath
.
If the ObjectPath
is a root path then None
is returned.
Returns an Iterator
over the elements of an ObjectPath
.
Trait Implementations
Performs the conversion.
Immutably borrows from an owned value. Read more
Returns the “default value” for a type. Read more
type Target = ObjectPath
type Target = ObjectPath
The resulting type after dereferencing.
Performs the conversion.
Performs the conversion.
Performs the conversion.
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for ObjectPathBuf
impl Send for ObjectPathBuf
impl Sync for ObjectPathBuf
impl Unpin for ObjectPathBuf
impl UnwindSafe for ObjectPathBuf
Blanket Implementations
Mutably borrows from an owned value. Read more