Expand description
§as_base
This crate allows directly accessing fields within a trait object similar to C++ public base classes. No virtual dispatch is involved, the base object always begins at the same address as the enclosing object.
use as_base::*;
struct BaseType {
x: u64,
}
trait MyTrait: AsBase<BaseType> {}
#[derive(AsBase)]
#[repr(C)]
struct Implementor {
pub base: BaseType,
}
impl MyTrait for Implementor {}
fn main() {
let x = Implementor {
base: BaseType { x: 42 },
};
let dyn_reference = &x as &dyn MyTrait;
assert_eq!(dyn_reference.as_base().x, 42)
}Traits§
- AsBase
- Marker trait for base casting.
- AsBase
Mut - Marker trait to indicate that transmuting
&mut Selfto&mut Tis safe. - AsBase
MutExt - Extension method for AsBaseMut .
- AsBase
Pin - Marker trait to indicate that transmuting
std::pin::Pin<&Self>tostd::pin::Pin<&T>is safe. - AsBase
PinExt - Extension method for AsBasePin .
- AsBase
PinMut - Marker trait to indicate that transmuting
std::pin::Pin<&mut Self>tostd::pin::Pin<&mut T>is safe. - AsBase
PinMut Ext - Extension method for AsBasePinMut .
- AsBase
Ref - Marker trait to indicate that transmuting
&Selfto&Tis safe. - AsBase
RefExt - Extension method for AsBaseRef .