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
impl TypeErasedBox
Sourcepub fn doesnt_matter() -> Self
pub fn doesnt_matter() -> Self
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
impl TypeErasedBox
Sourcepub fn new<T: Send + Sync + Debug + 'static>(value: T) -> Self
pub fn new<T: Send + Sync + Debug + 'static>(value: T) -> Self
Create a new TypeErasedBox from value of type T
Sourcepub fn new_with_clone<T: Send + Sync + Clone + Debug + 'static>(
value: T,
) -> Self
pub fn new_with_clone<T: Send + Sync + Clone + Debug + 'static>( value: T, ) -> Self
Create a new cloneable TypeErasedBox from the given value.
Sourcepub fn try_clone(&self) -> Option<Self>
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.
Sourcepub fn downcast<T: Debug + Send + Sync + 'static>(self) -> Result<Box<T>, Self>
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.
Trait Implementations§
Source§impl Debug for TypeErasedBox
impl Debug for TypeErasedBox
Source§impl From<TypeErasedError> for TypeErasedBox
impl From<TypeErasedError> for TypeErasedBox
Source§fn from(value: TypeErasedError) -> Self
fn from(value: TypeErasedError) -> Self
Auto Trait Implementations§
impl Freeze for TypeErasedBox
impl !RefUnwindSafe for TypeErasedBox
impl Send for TypeErasedBox
impl Sync for TypeErasedBox
impl Unpin for TypeErasedBox
impl !UnwindSafe for TypeErasedBox
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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