Struct 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::*;
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

Source

pub fn downcast_trait<T1: 'static + ?Sized>(&self) -> Option<&T1>

Downcasts the object into a reference of the given trait

Source

pub fn downcast_trait_mut<T1: 'static + ?Sized>(&mut self) -> Option<&mut T1>

Downcasts the object into a mutable reference of the given trait

Source

pub fn downcast_trait_boxed<T1: 'static + ?Sized>(self) -> Option<Box<T1>>

Downcasts the object to a boxed representation of the given trait

Source

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

Downcasts the object into a reference of the given type

Source

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

Downcasts the object into a mutable reference of the given type

Source

pub fn downcast<T: Any>(self) -> Option<T>

Downcasts the object into the given concrete type

Source

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

Source

pub fn implements<T: 'static + ?Sized>(&self) -> bool

Returns if the object implements a given trait

Trait Implementations§

Source§

impl Debug for MultitraitObject

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for MultitraitObject

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<T> From<T> for MultitraitObject
where T: IntoMultitrait,

Source§

fn from(other: T) -> Self

Converts to this type from the input type.
Source§

impl TryClone for MultitraitObject

Source§

fn try_clone(&self) -> Option<Self>

Source§

impl TryPartialEq for MultitraitObject

Source§

fn try_eq(&self, other: &Self) -> Option<bool>

Auto Trait Implementations§

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

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