Trait AccessAs

Source
pub trait AccessAs {
    // Required methods
    fn ref_as<T>(&self) -> Self::Guard<'_>
       where Self: IGuardRef<T>,
             T: ?Sized;
    fn mut_as<T>(&mut self) -> Self::GuardMut<'_>
       where Self: IGuardMut<T>,
             T: ?Sized;
}
Expand description

Provides access to a value as if it were of another type.

This is done by the following process:

  • memcopy self into copy
  • convert copy into target: ManuallyDrop<Target>
  • provide a guard that can Deref or DerefMut into target
  • upon dropping the mutable guard, convert target and assing target to self

This is always safe for non-self-referencial types.

Required Methods§

Source

fn ref_as<T>(&self) -> Self::Guard<'_>
where Self: IGuardRef<T>, T: ?Sized,

Provides immutable access to a type as if it were its ABI-unstable equivalent.

Source

fn mut_as<T>(&mut self) -> Self::GuardMut<'_>
where Self: IGuardMut<T>, T: ?Sized,

Provides mutable access to a type as if it were its ABI-unstable equivalent.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<Source> AccessAs for Source