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 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.

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.

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>

Get the bytes that make up an ObjectPath.

Get the ObjectPath as a &str.

Unlike ordinary std::path::Path, ObjectPaths are always valid Rust strs making this possible.

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.

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

The resulting type after dereferencing.

Dereferences the value.

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

The associated error which can be returned from parsing.

Parses a string s to return a value of this type. Read more

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Appends the signature of the type to the SignatureBuffer. Read more

If this returns true, it indicates that for implementing type T, Rust’s [T] is identical to DBus’s array format and can be copied into a message after aligning the first element. Read more

Check if this type fulfills this signature. This may expect to only be called with valid signatures. But it might be called with the wrong signature. This means for example you must check the length before indexing. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.