Macro rquickjs_core::class_def
source · [−]macro_rules! class_def {
($name:ident $($rest:tt)*) => { ... };
(@parse ($proto:ident) { $($body:tt)* } $($rest:tt)*) => { ... };
(@parse ($ctx:ident, $proto:ident) { $($body:tt)* } $($rest:tt)*) => { ... };
(@parse @($ctor:ident) { $($body:tt)* } $($rest:tt)*) => { ... };
(@parse @($ctx:ident, $ctor:ident) { $($body:tt)* } $($rest:tt)*) => { ... };
(@parse ~($self:ident, $marker:ident) { $($body:tt)* } $($rest:tt)*) => { ... };
(@parse ~ $($rest:tt)*) => { ... };
(@parse) => { ... };
(@proto $ctx:ident $proto:ident $($body:tt)*) => { ... };
(@ctor $ctx:ident $ctor:ident $($body:tt)*) => { ... };
(@mark $self:ident $marker:ident $($body:tt)*) => { ... };
(@decl $name:ident $($body:tt)*) => { ... };
}Available on crate feature
classes only.Expand description
The macro to simplify class definition.
struct TestClass;
impl TestClass {
fn method(&self) {}
fn static_func() {}
}
class_def! {
TestClass
// optional prototype initializer
(proto) {
proto.set("method", Func::from(Method(TestClass::method)))?;
}
// optional static initializer
@(ctor) {
ctor.set("static_func", Func::from(TestClass::static_func))?;
}
// optional internal refs marker (for gc)
~(_self, _marker) {
// mark internal refs if exists
}
}