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
Available on crate feature test-util
only.
pub fn doesnt_matter() -> Self
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
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
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
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