aws_smithy_types::type_erasure

Struct TypeErasedBox

Source
pub struct TypeErasedBox { /* private fields */ }
Expand description

Abstraction over Box<dyn T + Send + Sync> that provides Debug and optionally Clone.

The orchestrator uses TypeErasedBox to avoid the complication of six or more generic parameters and to avoid the monomorphization that brings with it.

§Examples

Creating a box:

use aws_smithy_types::type_erasure::TypeErasedBox;

let boxed = TypeErasedBox::new("some value");

Downcasting a box:

let value: Option<&String> = boxed.downcast_ref::<String>();

Converting a box back into its value:

let boxed = TypeErasedBox::new("some value".to_string());
let value: String = *boxed.downcast::<String>().expect("it is a string");

Implementations§

Source§

impl TypeErasedBox

Source

pub fn doesnt_matter() -> Self

Available on crate feature test-util only.

Often, when testing the orchestrator or its components, it’s necessary to provide a TypeErasedBox to serve as an Input for invoke. In cases where the type won’t actually be accessed during testing, use this method to generate a TypeErasedBox that makes it clear that “for the purpose of this test, the Input doesn’t matter.”

Source§

impl TypeErasedBox

Source

pub fn new<T: Send + Sync + Debug + 'static>(value: T) -> Self

Create a new TypeErasedBox from value of type T

Source

pub fn new_with_clone<T: Send + Sync + Clone + Debug + 'static>( value: T, ) -> Self

Create a new cloneable TypeErasedBox from the given value.

Source

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

Attempts to clone this box.

Note: this will only ever succeed if the box was created with TypeErasedBox::new_with_clone.

Source

pub fn downcast<T: Debug + Send + Sync + 'static>(self) -> Result<Box<T>, Self>

Downcast into a Box<T>, or return Self if it is not a T.

Source

pub fn downcast_ref<T: Debug + Send + Sync + 'static>(&self) -> Option<&T>

Downcast as a &T, or return None if it is not a T.

Source

pub fn downcast_mut<T: Debug + Send + Sync + 'static>( &mut self, ) -> Option<&mut T>

Downcast as a &mut T, or return None if it is not a T.

Trait Implementations§

Source§

impl Debug for TypeErasedBox

Source§

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

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

impl From<TypeErasedError> for TypeErasedBox

Source§

fn from(value: TypeErasedError) -> Self

Converts to this type from the input type.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.