Struct async_rustbus::rustbus_core::path::ObjectPathBuf[][src]

pub struct ObjectPathBuf { /* fields omitted */ }

Implementations

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 around Option<PathBuf>, where the None 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 that new 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]

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, ObjectPaths are always valid Rust strs making this possible.

pub fn strip_prefix<P: AsRef<Path> + ?Sized>(
    &self,
    p: &P
) -> Result<&ObjectPath, StripPrefixError>
[src]

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<Path> for ObjectPathBuf[src]

impl AsRef<str> for ObjectPathBuf[src]

impl Borrow<ObjectPath> for ObjectPathBuf[src]

impl Clone for ObjectPathBuf[src]

impl Debug for ObjectPathBuf[src]

impl Default for ObjectPathBuf[src]

impl Deref for ObjectPathBuf[src]

type Target = ObjectPath

The resulting type after dereferencing.

impl Display for ObjectPathBuf[src]

impl From<&'_ ObjectPath> for ObjectPathBuf[src]

impl From<ObjectPathBuf> for PathBuf[src]

impl From<ObjectPathBuf> for String[src]

impl FromStr for ObjectPathBuf[src]

type Err = InvalidObjectPath

The associated error which can be returned from parsing.

impl Hash for ObjectPathBuf[src]

impl Marshal for ObjectPathBuf[src]

impl Ord for ObjectPathBuf[src]

impl PartialEq<ObjectPath> for ObjectPathBuf[src]

impl PartialEq<ObjectPathBuf> for ObjectPathBuf[src]

impl PartialOrd<ObjectPathBuf> for ObjectPathBuf[src]

impl Signature for ObjectPathBuf[src]

impl TryFrom<&'_ OsStr> for ObjectPathBuf[src]

type Error = InvalidObjectPath

The type returned in the event of a conversion error.

impl TryFrom<&'_ Path> for ObjectPathBuf[src]

type Error = InvalidObjectPath

The type returned in the event of a conversion error.

impl TryFrom<&'_ str> for ObjectPathBuf[src]

type Error = InvalidObjectPath

The type returned in the event of a conversion error.

impl TryFrom<OsString> for ObjectPathBuf[src]

type Error = InvalidObjectPath

The type returned in the event of a conversion error.

impl TryFrom<PathBuf> for ObjectPathBuf[src]

type Error = InvalidObjectPath

The type returned in the event of a conversion error.

impl TryFrom<String> for ObjectPathBuf[src]

type Error = InvalidObjectPath

The type returned in the event of a conversion error.

impl<'buf, 'fds> Unmarshal<'buf, 'fds> for ObjectPathBuf[src]

impl Eq for ObjectPathBuf[src]

impl StructuralEq for ObjectPathBuf[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.