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 from_dyn(
identity: ExecutionContextIdentity,
value: &'a mut dyn Any,
) -> Self
pub fn from_dyn( identity: ExecutionContextIdentity, value: &'a mut dyn Any, ) -> Self
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>());Wrap an engine already erased to dyn Any, with the identity of its
concrete type.
§Examples
use tenferro_runtime::{ErasedExecutionContext, ExecutionContextIdentity};
let mut value = 7_u32;
let context = ErasedExecutionContext::from_dyn(ExecutionContextIdentity::of::<u32>(), &mut value);
assert_eq!(context.identity(), ExecutionContextIdentity::of::<u32>());pub fn identity(&self) -> ExecutionContextIdentity
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> !RefUnwindSafe for ErasedExecutionContext<'a>
impl<'a> !Send for ErasedExecutionContext<'a>
impl<'a> !Sync for ErasedExecutionContext<'a>
impl<'a> !UnwindSafe for ErasedExecutionContext<'a>
impl<'a> Freeze for ErasedExecutionContext<'a>
impl<'a> Unpin for ErasedExecutionContext<'a>
impl<'a> UnsafeUnpin 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