diff --git a/build.rs b/build.rs
index 321eedf1..0b0bf3ca 100644
--- a/build.rs
+++ b/build.rs
@@ -9,37 +9,39 @@ use std::path::{Path, PathBuf};
use std::process::Command;
fn find_it
(exe_name: P) -> Option
- where P: AsRef,
+where
+ P: AsRef,
{
env::var_os("PATH").and_then(|paths| {
- env::split_paths(&paths).filter_map(|dir| {
- let full_path = dir.join(&exe_name);
- if full_path.is_file() {
- Some(full_path)
- } else {
- None
- }
- }).next()
+ env::split_paths(&paths)
+ .filter_map(|dir| {
+ let full_path = dir.join(&exe_name);
+ if full_path.is_file() {
+ Some(full_path)
+ } else {
+ None
+ }
+ })
+ .next()
})
}
fn main() {
let node_include_path = find_it("node")
.expect("can not find executable node")
- .parent().unwrap()
- .parent().unwrap()
+ .parent()
+ .unwrap()
+ .parent()
+ .unwrap()
.join("include/node");
let node_version = semver::Version::parse(
- String::from_utf8(Command::new("node")
- .arg("-v")
- .output()
- .unwrap().stdout
- )
+ String::from_utf8(Command::new("node").arg("-v").output().unwrap().stdout)
.unwrap()
.as_str()
.get(1..)
- .unwrap()
- ).unwrap();
+ .unwrap(),
+ )
+ .unwrap();
let node_major_version = node_version.major;
@@ -53,13 +55,16 @@ fn main() {
// Activate the "node8" or "nodestable" feature for compatibility with
// different versions of Node.js/N-API.
- println!("cargo:rustc-cfg=node{}", if node_major_version > 8 {
- "stable"
- } else if node_major_version == 8 {
- "8"
- } else {
- panic!("node version is too low")
- });
+ println!(
+ "cargo:rustc-cfg=node{}",
+ if node_major_version > 8 {
+ "stable"
+ } else if node_major_version == 8 {
+ "8"
+ } else {
+ panic!("node version is too low")
+ }
+ );
bindgen::Builder::default()
.header("src/sys/bindings.h")
diff --git a/rustfmt.toml b/rustfmt.toml
new file mode 100644
index 00000000..b196eaa2
--- /dev/null
+++ b/rustfmt.toml
@@ -0,0 +1 @@
+tab_spaces = 2
diff --git a/scripts/napi.js b/scripts/napi.js
index e37e8686..a89d519e 100755
--- a/scripts/napi.js
+++ b/scripts/napi.js
@@ -27,7 +27,7 @@ const nodeIncludePath = path.join(
'node',
)
-const moduleName = path.basename(process.cwd()).replace('-', '_')
+const moduleName = path.basename(process.cwd()).replace(/-/g, '_')
process.env.NODE_INCLUDE_PATH = nodeIncludePath
process.env.NODE_MAJOR_VERSION = nodeMajorVersion > 8 ? 'stable' : 8
diff --git a/src/executor.rs b/src/executor.rs
index 113f51ab..ca7ee1f5 100644
--- a/src/executor.rs
+++ b/src/executor.rs
@@ -61,7 +61,7 @@ impl Task {
fn poll_future(&mut self) -> bool {
match self.spawn.poll_future_notify(&self.notify_handle, 0) {
Ok(Async::Ready(_)) => {
- let mut handle = self.notify_handle.0.write().unwrap().take().unwrap();
+ let handle = self.notify_handle.0.write().unwrap().take().unwrap();
handle.close();
true
}
diff --git a/src/lib.rs b/src/lib.rs
index 94b44a06..480c4cd2 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -33,10 +33,14 @@ pub struct Any;
pub struct Undefined;
#[derive(Clone, Copy, Debug)]
-pub struct Boolean;
+pub struct Boolean {
+ value: bool,
+}
#[derive(Clone, Copy, Debug)]
-pub struct Number;
+pub struct Number {
+ int: i64,
+}
#[derive(Clone, Copy, Debug)]
pub struct String;
@@ -48,13 +52,16 @@ pub struct Object;
pub struct Function;
#[derive(Clone, Copy, Debug)]
-pub struct Buffer;
+pub struct Buffer {
+ data: *const u8,
+ size: usize,
+}
#[derive(Clone, Copy, Debug)]
pub struct Value<'env, T> {
env: &'env Env,
raw_value: sys::napi_value,
- _marker: PhantomData,
+ value: T,
}
pub struct Ref {
@@ -219,14 +226,14 @@ impl Env {
let mut raw_value = ptr::null_mut();
let status = unsafe { sys::napi_get_undefined(self.0, &mut raw_value) };
debug_assert!(Status::from(status) == Status::Ok);
- Value::from_raw(self, raw_value)
+ Value::from_raw_value(self, raw_value, Undefined)
}
pub fn get_boolean(&self, value: bool) -> Value {
let mut raw_value = ptr::null_mut();
let status = unsafe { sys::napi_get_boolean(self.0, value, &mut raw_value) };
debug_assert!(Status::from(status) == Status::Ok);
- Value::from_raw(self, raw_value)
+ Value::from_raw_value(self, raw_value, Boolean { value })
}
pub fn create_int64<'a>(&'a self, int: i64) -> Value<'a, Number> {
@@ -234,7 +241,7 @@ impl Env {
let status =
unsafe { sys::napi_create_int64(self.0, int, (&mut raw_value) as *mut sys::napi_value) };
debug_assert!(Status::from(status) == Status::Ok);
- Value::from_raw(self, raw_value)
+ Value::from_raw_value(self, raw_value, Number { int })
}
pub fn create_string<'a, 'b>(&'a self, s: &'b str) -> Value<'a, String> {
@@ -243,7 +250,7 @@ impl Env {
sys::napi_create_string_utf8(self.0, s.as_ptr() as *const c_char, s.len(), &mut raw_value)
};
debug_assert!(Status::from(status) == Status::Ok);
- Value::from_raw(self, raw_value)
+ Value::from_raw_value(self, raw_value, String)
}
pub fn create_string_utf16<'a, 'b>(&'a self, chars: &[u16]) -> Value<'a, String> {
@@ -251,29 +258,52 @@ impl Env {
let status =
unsafe { sys::napi_create_string_utf16(self.0, chars.as_ptr(), chars.len(), &mut raw_value) };
debug_assert!(Status::from(status) == Status::Ok);
- Value::from_raw(self, raw_value)
+ Value::from_raw_value(self, raw_value, String)
}
pub fn create_object<'a>(&'a self) -> Value<'a, Object> {
let mut raw_value = ptr::null_mut();
let status = unsafe { sys::napi_create_object(self.0, &mut raw_value) };
debug_assert!(Status::from(status) == Status::Ok);
- Value::from_raw(self, raw_value)
+ Value::from_raw_value(self, raw_value, Object)
}
pub fn create_array_with_length(&self, length: usize) -> Value