Struct druid::piet::cairo::glib::variant::Variant

pub struct Variant { /* private fields */ }
Expand description

A generic immutable value capable of carrying various types.

See the module documentation for more details.

Implementations§

§

impl Variant

pub fn as_ptr(&self) -> *mut GVariant

Return the inner pointer to the underlying C value.

§

impl Variant

pub fn type_(&self) -> &VariantTy

Returns the type of the value.

pub fn is<T>(&self) -> boolwhere T: StaticVariantType,

Returns true if the type of the value corresponds to T.

pub fn is_type(&self, type_: &VariantTy) -> bool

Returns true if the type of the value corresponds to type_.

This is equivalent to self.type_().is_subtype_of(type_).

pub fn classify(&self) -> VariantClass

Returns the classification of the variant.

pub fn get<T>(&self) -> Option<T>where T: FromVariant,

Tries to extract a value of type T.

Returns Some if T matches the variant’s type.

pub fn try_get<T>(&self) -> Result<T, VariantTypeMismatchError>where T: FromVariant,

Tries to extract a value of type T.

pub fn from_variant(value: &Variant) -> Variant

Boxes value.

pub fn as_variant(&self) -> Option<Variant>

Unboxes self.

Returns Some if self contains a Variant.

pub fn child_value(&self, index: usize) -> Variant

Reads a child item out of a container Variant instance.

Panics
  • if self is not a container type.
  • if given index is larger than number of children.

pub fn try_child_value(&self, index: usize) -> Option<Variant>

Try to read a child item out of a container Variant instance.

It returns None if self is not a container type or if the given index is larger than number of children.

pub fn try_child_get<T>( &self, index: usize ) -> Result<Option<T>, VariantTypeMismatchError>where T: StaticVariantType + FromVariant,

Try to read a child item out of a container Variant instance.

It returns Ok(None) if self is not a container type or if the given index is larger than number of children. An error is thrown if the type does not match.

pub fn child_get<T>(&self, index: usize) -> Twhere T: StaticVariantType + FromVariant,

Read a child item out of a container Variant instance.

Panics
  • if self is not a container type.
  • if given index is larger than number of children.
  • if the expected variant type does not match

pub fn str(&self) -> Option<&str>

Tries to extract a &str.

Returns Some if the variant has a string type (s, o or g type strings).

pub fn fixed_array<T>(&self) -> Result<&[T], VariantTypeMismatchError>where T: FixedSizeVariantType,

Tries to extract a &[T] from a variant of array type with a suitable element type.

Returns an error if the type is wrong.

pub fn array_from_iter<T>( children: impl IntoIterator<Item = Variant> ) -> Variantwhere T: StaticVariantType,

Creates a new Variant array from children.

Panics

This function panics if not all variants are of type T.

pub fn array_from_iter_with_type( type_: &VariantTy, children: impl IntoIterator<Item = impl AsRef<Variant>> ) -> Variant

Creates a new Variant array from children with the specified type.

Panics

This function panics if not all variants are of type type_.

pub fn array_from_fixed_array<T>(array: &[T]) -> Variantwhere T: FixedSizeVariantType,

Creates a new Variant array from a fixed array.

pub fn tuple_from_iter( children: impl IntoIterator<Item = impl AsRef<Variant>> ) -> Variant

Creates a new Variant tuple from children.

pub fn from_dict_entry(key: &Variant, value: &Variant) -> Variant

Creates a new dictionary entry Variant.

DictEntry should be preferred over this when the types are known statically.

pub fn from_maybe<T>(child: Option<&Variant>) -> Variantwhere T: StaticVariantType,

Creates a new maybe Variant.

pub fn from_some(child: &Variant) -> Variant

Creates a new maybe Variant from a child.

pub fn from_none(type_: &VariantTy) -> Variant

Creates a new maybe Variant with Nothing.

pub fn as_maybe(&self) -> Option<Variant>

Extract the value of a maybe Variant.

Returns the child value, or None if the value is Nothing.

Panics

Panics if compiled with debug_assertions and the variant is not maybe-typed.

pub fn print(&self, type_annotate: bool) -> GString

Pretty-print the contents of this variant in a human-readable form.

A variant can be recreated from this output via Variant::parse.

pub fn parse(type_: Option<&VariantTy>, text: &str) -> Result<Variant, Error>

Parses a GVariant from the text representation produced by print().

pub fn from_bytes<T>(bytes: &Bytes) -> Variantwhere T: StaticVariantType,

Constructs a new serialized-mode GVariant instance.

pub unsafe fn from_bytes_trusted<T>(bytes: &Bytes) -> Variantwhere T: StaticVariantType,

Constructs a new serialized-mode GVariant instance.

This is the same as from_bytes, except that checks on the passed data are skipped.

You should not use this function on data from external sources.

Safety

Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.

pub fn from_data<T, A>(data: A) -> Variantwhere T: StaticVariantType, A: AsRef<[u8]>,

Constructs a new serialized-mode GVariant instance.

pub unsafe fn from_data_trusted<T, A>(data: A) -> Variantwhere T: StaticVariantType, A: AsRef<[u8]>,

Constructs a new serialized-mode GVariant instance.

This is the same as from_data, except that checks on the passed data are skipped.

You should not use this function on data from external sources.

Safety

Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.

pub fn from_bytes_with_type(bytes: &Bytes, type_: &VariantTy) -> Variant

Constructs a new serialized-mode GVariant instance with a given type.

pub unsafe fn from_bytes_with_type_trusted( bytes: &Bytes, type_: &VariantTy ) -> Variant

Constructs a new serialized-mode GVariant instance with a given type.

This is the same as from_bytes, except that checks on the passed data are skipped.

You should not use this function on data from external sources.

Safety

Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.

pub fn from_data_with_type<A>(data: A, type_: &VariantTy) -> Variantwhere A: AsRef<[u8]>,

Constructs a new serialized-mode GVariant instance with a given type.

pub unsafe fn from_data_with_type_trusted<A>( data: A, type_: &VariantTy ) -> Variantwhere A: AsRef<[u8]>,

Constructs a new serialized-mode GVariant instance with a given type.

This is the same as from_data, except that checks on the passed data are skipped.

You should not use this function on data from external sources.

Safety

Since the data is not validated, this is potentially dangerous if called on bytes which are not guaranteed to have come from serialising another Variant. The caller is responsible for ensuring bad data is not passed in.

pub fn data_as_bytes(&self) -> Bytes

Returns the serialized form of a GVariant instance.

pub fn data(&self) -> &[u8]

Returns the serialized form of a GVariant instance.

pub fn size(&self) -> usize

Returns the size of serialized form of a GVariant instance.

pub fn store(&self, data: &mut [u8]) -> Result<usize, BoolError>

Stores the serialized form of a GVariant instance into the given slice.

The slice needs to be big enough.

pub fn normal_form(&self) -> Variant

Returns a copy of the variant in normal form.

pub fn byteswap(&self) -> Variant

Returns a copy of the variant in the opposite endianness.

pub fn n_children(&self) -> usize

Determines the number of children in a container GVariant instance.

pub fn iter(&self) -> VariantIter

Create an iterator over items in the variant.

Note that this heap allocates a variant for each element, which can be particularly expensive for large arrays.

pub fn array_iter_str( &self ) -> Result<VariantStrIter<'_>, VariantTypeMismatchError>

Create an iterator over borrowed strings from a GVariant of type as (array of string).

This will fail if the variant is not an array of with the expected child type.

A benefit of this API over Self::iter() is that it minimizes allocation, and provides strongly typed access.

let strs = &["foo", "bar"];
let strs_variant: glib::Variant = strs.to_variant();
for s in strs_variant.array_iter_str()? {
    println!("{}", s);
}

pub fn is_container(&self) -> bool

Return whether this Variant is a container type.

pub fn is_normal_form(&self) -> bool

Return whether this Variant is in normal form.

pub fn is_object_path(string: &str) -> bool

Return whether input string is a valid VariantClass::ObjectPath.

pub fn is_signature(string: &str) -> bool

Return whether input string is a valid VariantClass::Signature.

Trait Implementations§

§

impl AsRef<Variant> for Variant

§

fn as_ref(&self) -> &Variant

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

impl Clone for Variant

§

fn clone(&self) -> Variant

Returns a copy of the value. Read more
1.0.0 · source§

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

Performs copy-assignment from source. Read more
§

impl Debug for Variant

§

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

Formats the value using the given formatter. Read more
§

impl Display for Variant

§

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

Formats the value using the given formatter. Read more
§

impl From<Variant> for VariantDict

§

fn from(other: Variant) -> VariantDict

Converts to this type from the input type.
§

impl<T> FromIterator<T> for Variantwhere T: ToVariant + StaticVariantType,

§

fn from_iter<I>(iter: I) -> Variantwhere I: IntoIterator<Item = T>,

Creates a value from an iterator. Read more
§

impl FromStr for Variant

§

type Err = Error

The associated error which can be returned from parsing.
§

fn from_str(s: &str) -> Result<Variant, <Variant as FromStr>::Err>

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

impl FromVariant for Variant

§

fn from_variant(variant: &Variant) -> Option<Variant>

Tries to extract a value. Read more
§

impl Hash for Variant

§

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

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
§

impl PartialEq<Variant> for Variant

§

fn eq(&self, other: &Variant) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

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

impl PartialOrd<Variant> for Variant

§

fn partial_cmp(&self, other: &Variant) -> 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

This method 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

This method 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

This method 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

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

impl StaticType for Variant

§

fn static_type() -> Type

Returns the type identifier of Self.
§

impl StaticVariantType for Variant

§

fn static_variant_type() -> Cow<'static, VariantTy>

Returns the VariantType corresponding to Self.
§

impl ToVariant for Variant

§

fn to_variant(&self) -> Variant

Returns a Variant clone of self.
§

impl Eq for Variant

§

impl Send for Variant

§

impl Sync for Variant

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> AnyEq for Twhere T: Any + PartialEq<T>,

source§

fn equals(&self, other: &(dyn Any + 'static)) -> bool

source§

fn as_any(&self) -> &(dyn Any + 'static)

source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *const GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GPtrArray> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

§

impl<T> FromGlibPtrArrayContainerAsVec<<T as GlibPtrDefault>::GlibType, *mut GSList> for Twhere T: GlibPtrDefault + FromGlibPtrNone<<T as GlibPtrDefault>::GlibType> + FromGlibPtrFull<<T as GlibPtrDefault>::GlibType>,

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

const: unstable · 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.

§

impl<T> RoundFrom<T> for T

§

fn round_from(x: T) -> T

Performs the conversion.
§

impl<T, U> RoundInto<U> for Twhere U: RoundFrom<T>,

§

fn round_into(self) -> U

Performs the conversion.
source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
§

impl<T> StaticTypeExt for Twhere T: StaticType,

§

fn ensure_type()

Ensures that the type has been registered with the type system.
§

impl<T> ToClosureReturnValue for Twhere T: ToValue,

source§

impl<T> ToOwned for Twhere T: Clone,

§

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
§

impl<T> ToSendValue for Twhere T: Send + ToValue + ?Sized,

§

fn to_send_value(&self) -> SendValue

Returns a SendValue clone of self.
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
§

impl<T> TryFromClosureReturnValue for Twhere T: for<'a> FromValue<'a> + StaticType + 'static,

source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
§

impl<'a, T, C, E> FromValueOptional<'a> for Twhere T: FromValue<'a, Checker = C>, C: ValueTypeChecker<Error = ValueTypeMismatchOrNoneError<E>>, E: Error + Send + 'static,