pub enum Signature {
}
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.
Structure(Fields)
The signature for a structure.
Implementations§
Source§impl Signature
impl Signature
Sourcepub const fn string_len(&self) -> usize
pub const fn string_len(&self) -> usize
The size of the string form of self
.
Sourcepub fn write_as_string_no_parens(&self, write: &mut impl Write) -> Result
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 (()
).
Sourcepub fn to_string_no_parens(&self) -> String
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 (()
).
Sourcepub fn to_string(&self) -> String
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.
Sourcepub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
pub fn from_bytes(bytes: &[u8]) -> Result<Self, Error>
Parse signature from a byte slice.
Sourcepub fn structure<F>(fields: F) -> Self
pub fn structure<F>(fields: F) -> Self
Create a Signature::Structure
for a given set of field signatures.
Sourcepub const fn static_structure(fields: &'static [&'static Signature]) -> Self
pub const fn static_structure(fields: &'static [&'static Signature]) -> Self
Create a Signature::Structure
for a given set of static field signatures.
Sourcepub const fn static_array(child: &'static Signature) -> Self
pub const fn static_array(child: &'static Signature) -> Self
Create a Signature::Array
for a given static child signature.
Sourcepub fn dict<K, V>(key: K, value: V) -> Self
pub fn dict<K, V>(key: K, value: V) -> Self
Create a Signature::Dict
for a given key and value signatures.
Sourcepub const fn static_dict(
key: &'static Signature,
value: &'static Signature,
) -> Self
pub const fn static_dict( key: &'static Signature, value: &'static Signature, ) -> Self
Create a Signature::Dict
for a given static key and value signatures.