Struct Variant

pub struct Variant<T> { /* private fields */ }
Expand description

Union container for manipulating an object from a heterogeneous set of types in a uniform manner.

Implementations§

§

impl<T> Variant<T>

pub const fn as_ptr(&self) -> *mut VariantWrapper

§

impl<T> Variant<T>

pub fn get_type(&self) -> Result<VariantDataType, Error>

Gets the data type of a Variant.

§

impl Variant<()>

pub fn cast<T>(self) -> Result<Option<Variant<T>>, Error>

Casts a generic Variant to a more specific type.

pub fn cast_ref<T>(&self) -> Result<Option<&Variant<T>>, Error>

Casts a generic Variant reference to a more specific type.

pub unsafe fn cast_unchecked<T>(self) -> Variant<T>

Casts a generic Variant to a more specific type.

§Safety

The caller must ensure that T matches the type stored in the Variant.

pub unsafe fn cast_ref_unchecked<T>(&self) -> &Variant<T>

Casts a generic Variant reference to a more specific type.

§Safety

The caller must ensure that T matches the type stored in the Variant.

§

impl<T> Variant<T>

pub fn create( domain: &Domain, value: <T as VariantConstraint>::DataArg<'_>, ) -> Result<Variant<T>, Error>

Creates a new Variant.

§Arguments
  • value - The initial value to store in the Variant.

pub fn get(&self) -> Result<<T as VariantConstraint>::RetArg, Error>

Returns the value stored in the Variant.

pub fn as_abstract(&self) -> &Variant<()>

Casts a Variant reference to its abstract representation.

pub fn to_abstract(self) -> Variant<()>

Casts a Variant to its abstract representation. Useful for returning a typed Variant in callbacks that expect a generic Variant.

Trait Implementations§

§

impl Debug for Variant<()>

§

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

Formats the value using the given formatter. Read more
§

impl<T> Debug for Variant<T>


let variant = Variant::<Vector2>::create(
    &domain,
    Vector2::ONE,
)?;
assert_eq!(
    format!("{variant:?}"),
    "Variant: vector2 = 'Vector2 { data: [1.0, 1.0] }'",
);
§

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<T> Display for Variant<T>

§

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

Formats the value using the given formatter. Read more
§

impl<T> Drop for Variant<T>

§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Variant<T>

§

impl<T> RefUnwindSafe for Variant<T>
where T: RefUnwindSafe,

§

impl<T> !Send for Variant<T>

§

impl<T> !Sync for Variant<T>

§

impl<T> Unpin for Variant<T>
where T: Unpin,

§

impl<T> UnwindSafe for Variant<T>
where T: UnwindSafe,

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
§

impl<T> AsAny for T
where T: 'static,

§

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

§

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

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Inherits<T> for T

§

fn upcast(self) -> Base

§

fn upcast_ref(&self) -> &Base

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