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§
Sourcefn downcast_ref<T: Any>(&self) -> Option<&T>
fn downcast_ref<T: Any>(&self) -> Option<&T>
Try to get a reference to the inner field if it is a T
.
Sourcefn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
Return a mutable reference to the inner field if it is a T
.
Sourcefn variant_is<T: Any>(&self) -> bool
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.