Struct aws_smithy_types::type_erasure::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
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
.