pub struct ErasedExecutionContext<'a> { /* private fields */ }Expand description
Type-erased execution context with a checked identity.
§Examples
use tenferro_runtime::{ErasedExecutionContext, ExecutionContextIdentity};
let mut value = 1_u64;
let erased = ErasedExecutionContext::new(&mut value);
assert_eq!(erased.identity(), ExecutionContextIdentity::of::<u64>());Implementations§
Source§impl<'a> ErasedExecutionContext<'a>
impl<'a> ErasedExecutionContext<'a>
Sourcepub fn new<T: 'static>(value: &'a mut T) -> Self
pub fn new<T: 'static>(value: &'a mut T) -> Self
Erase a concrete execution context while retaining its type identity.
§Examples
use tenferro_runtime::ErasedExecutionContext;
let mut value = 1_u64;
let erased = ErasedExecutionContext::new(&mut value);
assert_eq!(erased.identity().type_name(), std::any::type_name::<u64>());Sourcepub fn identity(&self) -> ExecutionContextIdentity
pub fn identity(&self) -> ExecutionContextIdentity
Return the stored execution-context type identity.
§Examples
use tenferro_runtime::{ErasedExecutionContext, ExecutionContextIdentity};
let mut value = 1_u64;
let erased = ErasedExecutionContext::new(&mut value);
assert_eq!(erased.identity(), ExecutionContextIdentity::of::<u64>());Sourcepub fn downcast_mut<T: 'static>(
&mut self,
expected: ExecutionContextIdentity,
) -> Result<&mut T, ExecutionContextMismatch>
pub fn downcast_mut<T: 'static>( &mut self, expected: ExecutionContextIdentity, ) -> Result<&mut T, ExecutionContextMismatch>
Downcast to the requested execution-context type after checking identity.
§Examples
use tenferro_runtime::{ErasedExecutionContext, ExecutionContextIdentity};
let mut value = 1_u64;
let mut erased = ErasedExecutionContext::new(&mut value);
*erased.downcast_mut::<u64>(ExecutionContextIdentity::of::<u64>())? = 2;§Errors
Returns ExecutionContextMismatch when the stored identity, supplied
expected identity, and requested type do not all agree.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ErasedExecutionContext<'a>
impl<'a> !RefUnwindSafe for ErasedExecutionContext<'a>
impl<'a> !Send for ErasedExecutionContext<'a>
impl<'a> !Sync for ErasedExecutionContext<'a>
impl<'a> Unpin for ErasedExecutionContext<'a>
impl<'a> UnsafeUnpin for ErasedExecutionContext<'a>
impl<'a> !UnwindSafe for ErasedExecutionContext<'a>
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
Mutably borrows from an owned value. Read more
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>
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 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>
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