Expand description
eXperimental Dynamic Casting for Rust
§Example
use xdc::*;
trait Parent : ObjBase {}
trait Foo : Parent {}
trait Bar : Parent {}
struct Test {}
xdc_struct!(Test);
impl Parent for Test {}
xdc_impl!(Parent, Test);
impl Foo for Test {}
xdc_impl!(Foo, Test);
impl Bar for Test {}
xdc_impl!(Bar, Test);
let mut example = Test {};
let foo_example: &dyn Foo = &example;
let bar_example: &dyn Bar = xdc::try_cast(foo_example).unwrap();
let foo_example_mut: &mut dyn Foo = &mut example;
let bar_example_mut: &mut dyn Bar = xdc::try_cast_mut(foo_example_mut).unwrap();
let foo_example_box: Box<dyn Foo> = Box::new(example);
let bar_example_box: Box<dyn Bar> = xdc::try_cast_boxed(foo_example_box).unwrap();
Re-exports§
pub use linkme;
Macros§
- metadata_
entry - Will be used to generate a MetadataEntry describing how to cast to
“
$type
struct being referred to using a$trait
trait object pointer” - mident
- Macro Identifier toolbox macro
- xdc_
impl - xdc_
impl_ - xdc_
struct - xdc_
struct_
Structs§
- FatPointer
- The Rust fat pointer structure as defined by the compiler
- Metadata
Entry - The metadata needed to allow for casting
Traits§
- ObjBase
- Base trait that will be added to all cast-able structs
Functions§
- try_
cast - Dynamic cast between immutable trait objects
- try_
cast_ boxed - Dynamic cast between Boxed trait objects
- try_
cast_ mut - Dynamic cast between mutable trait objects
- type_id
- Get a workaround for the TypeId of a given type