#[derive_ReprC(dyn, …)] usage
Summary
Given a simple Trait definition with signatures involving ReprC types exclusively, and using Traits as syntax for 'usability + Trait $(+ Send)? $(+ Sync)?, then:
-
annotating it with
#[derive_ReprC(dyn)](or
#[derive_ReprC(dyn, Clone)])when "Clone-annotating"),#![allow(unused)] fn main() { #[derive_ReprC(dyn, /* Clone */)] trait Trait /* : Send + Sync */ { } } -
makes
dyn Traits : ReprCTrait, which, in turn, -
makes
VirtualPtr<dyn Traits>become a legal/nameable type, so that:-
VirtualPtr<dyn Traits> : Traits, -
VirtualPtr<dyn Traits> : ReprCand thus, FFI-compatible, -
VirtualPtr<dyn Traits> : From<Box<impl Traits>>and so on for the other most pervasive Rust "smart" pointer types, -
In the case of
#[derive_ReprC(dyn, Clone)], we'll also have:-
VirtualPtr<dyn Traits> : Clone, -
From<{A,}Rc<impl Traits>>,
But at the cost of losing the
Fromimpls for&mutandBox<impl !Clone>. -
-
From<&impl Traits>(andFrom<{A,}Rc<impl Traits>>) will only be available when there are no&mut selfmethods in the trait definition.
-
A simple Trait definition?
A Trait definition is deemed simple if:
- it only has methods in it (
fn method(self: …, …)); - is
dyn-safe (no generics, nowhere Self : Sized); - with only
&Selfand&mut Selfreceiver types (the owned case is not supported yet).Pin<>-wrapping them is, however, accepted (thereby making theFromimpls require it).