neon-bindings / rfcs

RFCs for changes to Neon
Apache License 2.0
14 stars 9 forks source link

Pre-RFC: Procedural macro classes for N-API backend #37

Open kjvalencik opened 3 years ago

kjvalencik commented 3 years ago

Proc macro for classes

Replaces https://github.com/neon-bindings/rfcs/issues/6

Proc macros might allow creating classes as wrappers around the JsBox concept. For example:

struct MyClass {}

impl neon::JsClass for MyClass {
    fn init(cx: FunctionContext) -> Self { todo!() }
}

#[neon::class]
impl MyClass {
    #[neon::class_method(name = "myMethod")]
    my_method(cx: FunctionContext) -> Self {}
}

A use case to keep in my is re-using implementations. For example, a user might have both MemorySession and a RedisSession classes that share implementations. These should be friendly to generics and re-using the base class.