Struct multi_trait_object::MultitraitObject
source · [−]pub struct MultitraitObject { /* private fields */ }Expand description
A container to store data with the associated type and trait objects allowing for casting down to trait_impl or the concrete type
use multi_trait_object::prelude::*;
use std::fmt::{Debug, Display};
let mut mto = MultitraitObject::new(String::new());
register_traits!(mto, String, dyn Debug, dyn Display);
let debug = mto.downcast_trait::<dyn Debug>().unwrap();
println!("{:?}", debug);
let display = mto.downcast_trait::<dyn Display>().unwrap();
println!("{}", display);
let string = mto.downcast::<String>().unwrap();
println!("{}", string);Implementations
sourceimpl MultitraitObject
impl MultitraitObject
sourcepub fn new<T: 'static + Any>(value: T) -> Self
pub fn new<T: 'static + Any>(value: T) -> Self
Creates a new multitrait object from the given value All trait_impl except Any must be registered on this object in order to access them.
sourcepub fn downcast_trait<T1: 'static + ?Sized>(&self) -> Option<&T1>
pub fn downcast_trait<T1: 'static + ?Sized>(&self) -> Option<&T1>
Downcasts the object into a reference of the given trait
sourcepub fn downcast_trait_mut<T1: 'static + ?Sized>(&mut self) -> Option<&mut T1>
pub fn downcast_trait_mut<T1: 'static + ?Sized>(&mut self) -> Option<&mut T1>
Downcasts the object into a mutable reference of the given trait
sourcepub fn downcast_trait_boxed<T1: 'static + ?Sized>(self) -> Option<Box<T1>>
pub fn downcast_trait_boxed<T1: 'static + ?Sized>(self) -> Option<Box<T1>>
Downcasts the object to a boxed representation of the given trait
sourcepub fn downcast_ref<T: Any>(&self) -> Option<&T>
pub fn downcast_ref<T: Any>(&self) -> Option<&T>
Downcasts the object into a reference of the given type
sourcepub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
pub fn downcast_mut<T: Any>(&mut self) -> Option<&mut T>
Downcasts the object into a mutable reference of the given type
sourcepub fn is<T: Any>(&self) -> bool
pub fn is<T: Any>(&self) -> bool
Returns if the object stores the given concrete type Use MultitraitObject::implements to check if the object has a given trait
sourcepub fn implements<T: 'static + ?Sized>(&self) -> bool
pub fn implements<T: 'static + ?Sized>(&self) -> bool
Returns if the object implements a given trait
Trait Implementations
sourceimpl Debug for MultitraitObject
impl Debug for MultitraitObject
sourceimpl Drop for MultitraitObject
impl Drop for MultitraitObject
sourceimpl<T> From<T> for MultitraitObject where
T: IntoMultitrait,
impl<T> From<T> for MultitraitObject where
T: IntoMultitrait,
Auto Trait Implementations
impl RefUnwindSafe for MultitraitObject
impl !Send for MultitraitObject
impl !Sync for MultitraitObject
impl Unpin for MultitraitObject
impl UnwindSafe for MultitraitObject
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more