Macro to implement inherit
Provide class
to cover a struct itself, it's impl and trait implements that need to inherit.
To borrow as mut, see defasmut
macro class
need to wrap struct and implements.
using #[keep]
for method make that method keep in the original impl.
methods without #[keep]
will be put into trait __XXX__
.
and macro will auto generate a new
function which return Pin
.
expression in the method will be converted.
instead of use self
, using this
.
self
will be convert to use unsafe { self.__real__.as_ref().unwrap() }
.
selfmut
will be convert to use unsafe { self.__real__.asmut().unwrap() }
.
_super
will be convert to use self.__prototype__
.
_supermut
will be convert to use unsafe { self.__prototype__.asmut().getuncheckedmut() }
.
macro defasmut
this macro will define macro as_mut
example:
```rust
class! {
struct Example {
data: String
}
impl Example {
#[keep]
fn with() -> Pin
fn set_data(&mut self, data: String) {
this.data = data;
}
fn get_data(&self) -> String {
this.data.clone()
}
}
impl Something for Example {
//do something
}
}
class! {
extends Example;
struct Sub { }
impl Sub { }
}
the struct will become:
rust
struct Example {
real: *mut dyn Example,
pinned: ::std::marker::PhantomPinned,
data: String
}
struct Sub {
prototype: ::std::pin::Pin
to borrow as mut:
rust
def
fn main() { let mut example = Sub::new("data".tostring()); asmut!(example).setdata("modified".tostring()); asserteq!(example.getdata(), "modified".to_string()); } ```