Init
This commit is contained in:
41
rust_native_module/src/lib.rs
Normal file
41
rust_native_module/src/lib.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
use neon::prelude::*;
|
||||
|
||||
fn hello(mut cx: FunctionContext) -> JsResult<JsString> {
|
||||
Ok(cx.string("hello from rust 🦀"))
|
||||
}
|
||||
|
||||
struct MyStruct {
|
||||
name: String,
|
||||
}
|
||||
|
||||
impl MyStruct {
|
||||
fn new(name: String) -> Self {
|
||||
println!("NEW {}", &name);
|
||||
Self { name }
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for MyStruct {
|
||||
fn drop(&mut self) {
|
||||
println!("DROP {}", self.name);
|
||||
}
|
||||
}
|
||||
|
||||
impl Finalize for MyStruct {
|
||||
fn finalize<'a, C: Context<'a>>(self, _: &mut C) {
|
||||
println!("FINALIZE {}", self.name);
|
||||
}
|
||||
}
|
||||
|
||||
fn test_box(mut cx: FunctionContext) -> JsResult<JsBox<MyStruct>> {
|
||||
let my_struct = MyStruct::new("Test Struct ayayay".to_string());
|
||||
|
||||
Ok(cx.boxed(my_struct))
|
||||
}
|
||||
|
||||
#[neon::main]
|
||||
fn main(mut cx: ModuleContext) -> NeonResult<()> {
|
||||
cx.export_function("hello", hello)?;
|
||||
cx.export_function("gib_box", test_box)?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user