Struct FilePath

Source
pub struct FilePath<'f>(Cow<'f, CStr>);
Expand description

File name represented as a nul-terminated byte array.

While zvariant::Type and serde::{Serialize, Deserialize}, are implemented for Path and PathBuf, unfortunately serde serializes them as UTF-8 strings and that limits the number of possible characters to use on a file path. This is not the desired behavior since file paths are not guaranteed to contain only UTF-8 characters.

To solve this problem, this type is provided which encodes the underlying file path as a null-terminated byte array.

§Examples:

use zvariant::FilePath;
use std::path::{Path, PathBuf};

let path = Path::new("/hello/world\0");
let path_buf = PathBuf::from(path);

let p1 = FilePath::from(path);
let p2 = FilePath::from(path_buf);
let p3 = FilePath::from("/hello/world");

assert_eq!(p1, p2);
assert_eq!(p2, p3);

Tuple Fields§

§0: Cow<'f, CStr>

Implementations§

Source§

impl<'f> FilePath<'f>

Source

pub fn new(cow: Cow<'f, CStr>) -> Self

Trait Implementations§

Source§

impl<'f> AsRef<FilePath<'f>> for FilePath<'f>

Source§

fn as_ref(&self) -> &FilePath<'f>

Converts this type into a shared reference of the (usually inferred) input type.
Source§

impl<'f> Clone for FilePath<'f>

Source§

fn clone(&self) -> FilePath<'f>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'f> Debug for FilePath<'f>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'f> Default for FilePath<'f>

Source§

fn default() -> FilePath<'f>

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

impl<'de, 'f> Deserialize<'de> for FilePath<'f>

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<'f> From<&'f CStr> for FilePath<'f>

Source§

fn from(value: &'f CStr) -> Self

Converts to this type from the input type.
Source§

impl<'f> From<&'f CString> for FilePath<'f>

Source§

fn from(value: &'f CString) -> Self

Converts to this type from the input type.
Source§

impl<'f> From<&'f FilePath<'f>> for &'f Path

Source§

fn from(value: &'f FilePath<'f>) -> Self

Converts to this type from the input type.
Source§

impl<'f> From<&'f OsStr> for FilePath<'f>

Source§

fn from(value: &'f OsStr) -> FilePath<'f>

Converts to this type from the input type.
Source§

impl<'f> From<&'f OsString> for FilePath<'f>

Source§

fn from(value: &'f OsString) -> FilePath<'f>

Converts to this type from the input type.
Source§

impl<'f> From<&'f Path> for FilePath<'f>

Source§

fn from(value: &'f Path) -> Self

Converts to this type from the input type.
Source§

impl<'f> From<&'f PathBuf> for FilePath<'f>

Source§

fn from(value: &'f PathBuf) -> FilePath<'f>

Converts to this type from the input type.
Source§

impl<'f> From<&'f str> for FilePath<'f>

Source§

fn from(value: &'f str) -> Self

Converts to this type from the input type.
Source§

impl From<CString> for FilePath<'_>

Source§

fn from(value: CString) -> Self

Converts to this type from the input type.
Source§

impl From<FilePath<'_>> for OsString

Source§

fn from(value: FilePath<'_>) -> Self

Converts to this type from the input type.
Source§

impl<'f> From<FilePath<'f>> for PathBuf

Source§

fn from(value: FilePath<'f>) -> Self

Converts to this type from the input type.
Source§

impl From<OsString> for FilePath<'_>

Source§

fn from(value: OsString) -> Self

Converts to this type from the input type.
Source§

impl From<PathBuf> for FilePath<'_>

Source§

fn from(value: PathBuf) -> FilePath<'static>

Converts to this type from the input type.
Source§

impl<'f> Ord for FilePath<'f>

Source§

fn cmp(&self, other: &FilePath<'f>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<'f> PartialEq for FilePath<'f>

Source§

fn eq(&self, other: &FilePath<'f>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<'f> PartialOrd for FilePath<'f>

Source§

fn partial_cmp(&self, other: &FilePath<'f>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<'f> Serialize for FilePath<'f>

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'f> Type for FilePath<'f>

Source§

const SIGNATURE: &'static Signature

The signature for the implementing type, in parsed format. Read more
Source§

impl<'f> Eq for FilePath<'f>

Source§

impl<'f> StructuralPartialEq for FilePath<'f>

Auto Trait Implementations§

§

impl<'f> Freeze for FilePath<'f>

§

impl<'f> RefUnwindSafe for FilePath<'f>

§

impl<'f> Send for FilePath<'f>

§

impl<'f> Sync for FilePath<'f>

§

impl<'f> Unpin for FilePath<'f>

§

impl<'f> UnwindSafe for FilePath<'f>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<'de, T> DynamicDeserialize<'de> for T
where T: Type + Deserialize<'de>,

Source§

type Deserializer = PhantomData<T>

A DeserializeSeed implementation for this type.
Source§

fn deserializer_for_signature( signature: &Signature, ) -> Result<<T as DynamicDeserialize<'de>>::Deserializer, Error>

Get a deserializer compatible with this parsed signature.
Source§

impl<T> DynamicType for T
where T: Type + ?Sized,

Source§

fn signature(&self) -> Signature

The type signature for self. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> NoneValue for T
where T: Default,

Source§

type NoneType = T

Source§

fn null_value() -> T

The none-equivalent value.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,