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

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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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>,

§

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

§

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more