Enum Signature

Source
pub enum Signature {
Show 18 variants Unit, U8, Bool, I16, U16, I32, U32, I64, U64, F64, Str, Signature, ObjectPath, Variant, Fd, Array(Child), Dict { key: Child, value: Child, }, Structure(Fields),
}
Expand description

A D-Bus signature in parsed form.

This is similar to the zvariant::Signature type, but unlike zvariant::Signature, this is a parsed representation of a signature. Our (de)serialization API primarily uses this type for efficiency.

§Examples

Typically, you’d create a Signature from a string:

use std::str::FromStr;
use zvariant::Signature;

let sig = Signature::from_str("a{sv}").unwrap();
assert_eq!(sig.to_string(), "a{sv}");

let sig = Signature::from_str("(xa{bs}as)").unwrap();
assert_eq!(sig.to_string(), "(xa{bs}as)");

Variants§

§

Unit

The signature for the unit type (()). This is not a valid D-Bus signature, but is used to represnt “no data” (for example, a D-Bus method call without any arguments will have this as its body signature).

§Warning

This variant only exists for convenience and must only be used as a top-level signature. If used inside container signatures, it will cause errors and in somce cases, panics. It’s best to not use it directly.

§

U8

The signature for an 8-bit unsigned integer (AKA a byte).

§

Bool

The signature for a boolean.

§

I16

The signature for a 16-bit signed integer.

§

U16

The signature for a 16-bit unsigned integer.

§

I32

The signature for a 32-bit signed integer.

§

U32

The signature for a 32-bit unsigned integer.

§

I64

The signature for a 64-bit signed integer.

§

U64

The signature for a 64-bit unsigned integer.

§

F64

The signature for a 64-bit floating point number.

§

Str

The signature for a string.

§

Signature

The signature for a signature.

§

ObjectPath

The signature for an object path.

§

Variant

The signature for a variant.

§

Fd

The signature for a file descriptor.

§

Array(Child)

The signature for an array.

§

Dict

The signature for a dictionary.

Fields

§key: Child

The signature for the key.

§value: Child

The signature for the value.

§

Structure(Fields)

The signature for a structure.

Implementations§

Source§

impl Signature

Source

pub const fn string_len(&self) -> usize

The size of the string form of self.

Source

pub fn write_as_string_no_parens(&self, write: &mut impl Write) -> Result

Write the string form of self to the given formatter.

This produces the same output as the Display::fmt, unless self is a Signature::Structure, in which case the written string will not be wrapped in parenthesis (()).

Source

pub fn to_string_no_parens(&self) -> String

Convert self to a string, without any enclosing parenthesis.

This produces the same output as the Signature::to_string, unless self is a Signature::Structure, in which case the written string will not be wrapped in parenthesis (()).

Source

pub fn to_string(&self) -> String

Convert self to a string.

This produces the same output as the ToString::to_string, except it preallocates the required memory and hence avoids reallocations and moving of data.

Source

pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>

Parse signature from a byte slice.

Source

pub fn structure<F>(fields: F) -> Self
where F: Into<Fields>,

Create a Signature::Structure for a given set of field signatures.

Source

pub const fn static_structure(fields: &'static [&'static Signature]) -> Self

Create a Signature::Structure for a given set of static field signatures.

Source

pub fn array<C>(child: C) -> Self
where C: Into<Child>,

Create a Signature::Array for a given child signature.

Source

pub const fn static_array(child: &'static Signature) -> Self

Create a Signature::Array for a given static child signature.

Source

pub fn dict<K, V>(key: K, value: V) -> Self
where K: Into<Child>, V: Into<Child>,

Create a Signature::Dict for a given key and value signatures.

Source

pub const fn static_dict( key: &'static Signature, value: &'static Signature, ) -> Self

Create a Signature::Dict for a given static key and value signatures.

Source

pub fn alignment(&self, format: Format) -> usize

The required padding alignment for the given format.

Trait Implementations§

Source§

impl Clone for Signature

Source§

fn clone(&self) -> Signature

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 Debug for Signature

Source§

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

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

impl Default for Signature

Source§

fn default() -> Signature

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

impl<'de> Deserialize<'de> for Signature

Source§

fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error>

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

impl Display for Signature

Source§

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

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

impl From<&'static Signature> for Child

Source§

fn from(child: &'static Signature) -> Self

Converts to this type from the input type.
Source§

impl From<&Signature> for Signature

Source§

fn from(value: &Signature) -> Self

Converts to this type from the input type.
Source§

impl From<Signature> for Child

Source§

fn from(child: Signature) -> Self

Converts to this type from the input type.
Source§

impl FromStr for Signature

Source§

type Err = Error

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

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

impl Hash for Signature

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

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

impl Ord for Signature

Source§

fn cmp(&self, other: &Self) -> 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 PartialEq<&str> for Signature

Source§

fn eq(&self, other: &&str) -> 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 PartialEq<str> for Signature

Source§

fn eq(&self, other: &str) -> 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 PartialEq for Signature

Source§

fn eq(&self, other: &Self) -> 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 PartialOrd for Signature

Source§

fn partial_cmp(&self, other: &Self) -> 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 Serialize for Signature

Source§

fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error>

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

impl TryFrom<&[u8]> for Signature

Source§

type Error = Error

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

fn try_from(value: &[u8]) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl TryFrom<&str> for Signature

Source§

type Error = Error

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

fn try_from(value: &str) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Signature

Auto Trait Implementations§

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<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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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>,