Struct async_rustbus::rustbus_core::path::ObjectPathBuf [−][src]
pub struct ObjectPathBuf { /* fields omitted */ }
Implementations
impl ObjectPathBuf
[src]
impl ObjectPathBuf
[src]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.
pub fn new() -> ObjectPathBuf
[src]
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.
pub fn with_capacity(capacity: usize) -> ObjectPathBuf
[src]
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
.
pub fn as_object_path(&self) -> &ObjectPath
[src]
Coerces to a ObjectPath
slice.
pub fn clear(&mut self)
[src]
Truncates the object path into a root path.
This does not affect the capacity of the ObjectPathBuf
.
pub fn push(&mut self, path: &ObjectPath)
[src]
Append an ObjectPath
to this one.
pub fn push_path<P: AsRef<Path>>(&mut self, path: P)
[src]
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");
pub fn push_path_checked<P: AsRef<Path>>(
&mut self,
path: P
) -> Result<(), InvalidObjectPath>
[src]
&mut self,
path: P
) -> Result<(), InvalidObjectPath>
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();
pub fn pop(&mut self) -> bool
[src]
Truncate the ObjectPathBuf
to parent
.
Returns true if the path changed.
pub fn reserve(&mut self, additional: usize)
[src]
pub fn reserve_exact(&mut self, additional: usize)
[src]
pub fn capacity(&self) -> usize
[src]
Get the capacity of the current heap allocation.
If capacity is zero then there is no heap allocation, and the ObjectPathBuf
is a root path.
The root path is special case that can be stored without a heap allocation despite being length 1.
Methods from Deref<Target = ObjectPath>
pub fn as_bytes(&self) -> &[u8]
[src]
Get the bytes that make up an ObjectPath
.
pub fn as_str(&self) -> &str
[src]
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>
[src]
&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());
pub fn parent(&self) -> Option<&ObjectPath>
[src]
Get the parent of the ObjectPath
by removing the last element.
If the ObjectPath
is a root path then None
is returned.
pub fn file_name(&self) -> Option<&str>
[src]
Retrieves the last element of the ObjectPath
.
If the ObjectPath
is a root path then None
is returned.
pub fn components(&self) -> impl Iterator<Item = &str>
[src]
Returns an Iterator
over the elements of an ObjectPath
.
pub fn to_object_path_buf(&self) -> ObjectPathBuf
[src]
Trait Implementations
impl AsRef<ObjectPath> for ObjectPathBuf
[src]
impl AsRef<ObjectPath> for ObjectPathBuf
[src]fn as_ref(&self) -> &ObjectPath
[src]
impl Borrow<ObjectPath> for ObjectPathBuf
[src]
impl Borrow<ObjectPath> for ObjectPathBuf
[src]fn borrow(&self) -> &ObjectPath
[src]
impl Clone for ObjectPathBuf
[src]
impl Clone for ObjectPathBuf
[src]fn clone(&self) -> ObjectPathBuf
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Default for ObjectPathBuf
[src]
impl Default for ObjectPathBuf
[src]fn default() -> ObjectPathBuf
[src]
impl Deref for ObjectPathBuf
[src]
impl Deref for ObjectPathBuf
[src]type Target = ObjectPath
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl From<&'_ ObjectPath> for ObjectPathBuf
[src]
impl From<&'_ ObjectPath> for ObjectPathBuf
[src]fn from(path: &ObjectPath) -> Self
[src]
impl From<ObjectPathBuf> for PathBuf
[src]
impl From<ObjectPathBuf> for PathBuf
[src]fn from(buf: ObjectPathBuf) -> Self
[src]
impl From<ObjectPathBuf> for String
[src]
impl From<ObjectPathBuf> for String
[src]fn from(path: ObjectPathBuf) -> Self
[src]
impl FromStr for ObjectPathBuf
[src]
impl FromStr for ObjectPathBuf
[src]impl Hash for ObjectPathBuf
[src]
impl Hash for ObjectPathBuf
[src]impl Marshal for ObjectPathBuf
[src]
impl Marshal for ObjectPathBuf
[src]fn marshal(&self, ctx: &mut MarshalContext<'_, '_>) -> Result<(), Error>
[src]
pub fn marshal_as_variant(
&self,
ctx: &mut MarshalContext<'_, '_>
) -> Result<(), Error>
[src]
&self,
ctx: &mut MarshalContext<'_, '_>
) -> Result<(), Error>
impl Ord for ObjectPathBuf
[src]
impl Ord for ObjectPathBuf
[src]impl PartialEq<ObjectPath> for ObjectPathBuf
[src]
impl PartialEq<ObjectPath> for ObjectPathBuf
[src]impl PartialEq<ObjectPathBuf> for ObjectPathBuf
[src]
impl PartialEq<ObjectPathBuf> for ObjectPathBuf
[src]impl PartialOrd<ObjectPathBuf> for ObjectPathBuf
[src]
impl PartialOrd<ObjectPathBuf> for ObjectPathBuf
[src]fn partial_cmp(&self, other: &ObjectPathBuf) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl Signature for ObjectPathBuf
[src]
impl Signature for ObjectPathBuf
[src]impl TryFrom<&'_ OsStr> for ObjectPathBuf
[src]
impl TryFrom<&'_ OsStr> for ObjectPathBuf
[src]impl TryFrom<&'_ Path> for ObjectPathBuf
[src]
impl TryFrom<&'_ Path> for ObjectPathBuf
[src]impl TryFrom<&'_ str> for ObjectPathBuf
[src]
impl TryFrom<&'_ str> for ObjectPathBuf
[src]impl TryFrom<OsString> for ObjectPathBuf
[src]
impl TryFrom<OsString> for ObjectPathBuf
[src]impl TryFrom<PathBuf> for ObjectPathBuf
[src]
impl TryFrom<PathBuf> for ObjectPathBuf
[src]impl TryFrom<String> for ObjectPathBuf
[src]
impl TryFrom<String> for ObjectPathBuf
[src]impl<'buf, 'fds> Unmarshal<'buf, 'fds> for ObjectPathBuf
[src]
impl<'buf, 'fds> Unmarshal<'buf, 'fds> for ObjectPathBuf
[src]