napi-rs/examples/napi/src/symbol.rs
Tom Sherman 3418fd3e8f
feat(napi,sys): implement Symbol.for (#1721)
Co-authored-by: LongYinan <lynweklm@gmail.com>
2023-09-13 15:45:14 -07:00

18 lines
422 B
Rust

use napi::{bindgen_prelude::*, Env, JsObject, JsSymbol};
#[napi]
pub fn set_symbol_in_obj(env: Env, symbol: JsSymbol) -> Result<JsObject> {
let mut obj = env.create_object()?;
obj.set_property(symbol, env.create_string("a symbol")?)?;
Ok(obj)
}
#[napi]
pub fn create_symbol() -> Symbol {
Symbol::new("a symbol".to_owned())
}
#[napi]
pub fn create_symbol_for(desc: String) -> Symbol {
Symbol::for_desc(desc)
}