diff --git a/.gitignore b/.gitignore index 0b3cb79fd9fca0b6513ffc7fa9100a6c7f6b0a50..49b3073eefbf1f5035d839aaa18754fec0a13d45 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ native/artifacts.json **/*~ **/node_modules **/.DS_Store + +*.bk diff --git a/native/src/lib.rs b/native/src/lib.rs index 5b9929c08d926d106f800af00861c090731a3cdb..53b89a3d1c1dcb40b855cfd8fa13c1084892e7cc 100644 --- a/native/src/lib.rs +++ b/native/src/lib.rs @@ -1,14 +1,48 @@ +//! `duniter-rs-wotb-js` is a crate providing Javascript bindings of `duniter-rs-wotb`. + +#![deny(missing_docs, +/*missing_debug_implementations, */ +missing_copy_implementations, + trivial_casts, trivial_numeric_casts, + unsafe_code, + unstable_features, + unused_import_braces, unused_qualifications)] + #[macro_use] extern crate neon; +extern crate duniter_rs_wotb; + +use neon::vm::Throw; +use neon::js::{JsInteger, JsString}; +use duniter_rs_wotb::WebOfTrust; + + +declare_types! { + /// JS class wrapping WebOfTrust struct. + pub class JsWebOfTrust for WebOfTrust { + init(call) { + let scope = call.scope; + let arg0 = try!(call.arguments.require(scope, 0)); + + if let Ok(max_cert) = arg0.check::<JsInteger>() { + let max_cert = max_cert.value(); -use neon::vm::{Call, JsResult}; -use neon::js::JsString; + match max_cert > 0 { + true => Ok(WebOfTrust::new(max_cert as usize)), + false => Err(Throw), + } -fn hello(call: Call) -> JsResult<JsString> { - let scope = call.scope; - Ok(JsString::new(scope, "hello node").unwrap()) -} + + } else if let Ok(path) = arg0.check::<JsString>() { + let path = path.value(); -register_module!(m, { - m.export("hello", hello) -}); + match WebOfTrust::from_file(path.as_str()) { + Some(wot) => Ok(wot), + None => Err(Throw), + } + } else { + Err(Throw) + } + } + } +} \ No newline at end of file