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::*;
use std::fmt::{Debug, Display};
let mto = create_object!(String::new(), 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§
Source§impl MultitraitObject
impl MultitraitObject
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§
Source§impl Debug for MultitraitObject
impl Debug for MultitraitObject
Source§impl Drop for MultitraitObject
impl Drop for MultitraitObject
Source§impl<T> From<T> for MultitraitObjectwhere
T: IntoMultitrait,
impl<T> From<T> for MultitraitObjectwhere
T: IntoMultitrait,
Source§impl TryPartialEq for MultitraitObject
impl TryPartialEq for MultitraitObject
Auto Trait Implementations§
impl Freeze for MultitraitObject
impl RefUnwindSafe for MultitraitObject
impl !Send for MultitraitObject
impl !Sync for MultitraitObject
impl Unpin for MultitraitObject
impl UnwindSafe for MultitraitObject
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more