Macro vtable::new_vref[][src]

macro_rules! new_vref {
    (let $ident : ident : VRef < $vtable : ty > for $trait_ : path = $e : expr) => { ... };
    (let mut $ident : ident : VRefMut < $vtable : ty > for $trait_ : path = $e :
 expr) => { ... };
}
Expand description

Creates a VRef or a VRefMut suitable for an instance that implements the trait

When possible, VRef::new or VRefMut::new should be preferred, as they use a static vtable. But when using the generated XxxVTable_static! macro that is not possible and this macro can be used instead. Note that the downcast will not work with references created with this macro.

use vtable::*;
#[vtable]
struct MyVTable { /* ... */ }
struct Something { /* ... */};
impl My for Something {};

let mut s = Something { /* ... */};
// declare a my_vref variable for the said VTable
new_vref!(let my_vref : VRef<MyVTable> for My = &s);

// same but mutable
new_vref!(let mut my_vref_m : VRefMut<MyVTable> for My = &mut s);