Trait SumType

Source
pub trait SumType {
    // Required methods
    fn variant(&self) -> &'static str;
    fn variants(&self) -> &'static [&'static str];
    fn downcast_ref<T: Any>(&self) -> Option<&T>;
    fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>;
    fn variant_is<T: Any>(&self) -> bool;
}
Expand description

Various methods for introspection and dynamic typing.

§Note

This trait is automatically implemented for all types generated by the sum_type!() macro. You should never need to implement it manually.

Required Methods§

Source

fn variant(&self) -> &'static str

The name of the current variant.

Source

fn variants(&self) -> &'static [&'static str]

A list of all possible variants.

Source

fn downcast_ref<T: Any>(&self) -> Option<&T>

Try to get a reference to the inner field if it is a T.

Source

fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>

Return a mutable reference to the inner field if it is a T.

Source

fn variant_is<T: Any>(&self) -> bool

Is the underlying variant an instance of T?

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§