#![cfg_attr(docsrs, feature(doc_cfg))]
pub mod context;
pub mod event;
pub mod handle;
mod macros;
pub mod meta;
pub mod object;
pub mod prelude;
pub mod reflect;
pub mod result;
#[cfg(not(feature = "sys"))]
mod sys;
#[cfg_attr(docsrs, doc(cfg(feature = "napi-6")))]
#[cfg(feature = "napi-6")]
pub mod thread;
mod types_docs;
mod types_impl;
#[cfg(feature = "sys")]
#[cfg_attr(docsrs, doc(cfg(feature = "sys")))]
pub mod sys;
#[cfg(all(feature = "napi-6", feature = "futures"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "napi-6", feature = "futures"))))]
pub use executor::set_global_executor;
pub use types_docs::exports as types;
#[doc(hidden)]
pub mod macro_internal;
pub use crate::macros::*;
use crate::{context::ModuleContext, handle::Handle, result::NeonResult, types::JsValue};
#[cfg(feature = "napi-6")]
mod lifecycle;
#[cfg(all(feature = "napi-6", feature = "futures"))]
mod executor;
#[cfg(feature = "napi-8")]
static MODULE_TAG: once_cell::sync::Lazy<crate::sys::TypeTag> = once_cell::sync::Lazy::new(|| {
let mut lower = [0; std::mem::size_of::<u64>()];
getrandom::getrandom(&mut lower).expect("Failed to generate a Neon module type tag");
let lower = u64::from_ne_bytes(lower);
crate::sys::TypeTag { lower, upper: 1 }
});
pub struct Exports(());
impl Exports {
pub fn export(self, cx: &mut ModuleContext) -> NeonResult<()> {
for create in self {
let (name, value) = create(cx)?;
cx.export_value(name, value)?;
}
Ok(())
}
}
impl IntoIterator for Exports {
type Item = <<Self as IntoIterator>::IntoIter as IntoIterator>::Item;
type IntoIter = std::slice::Iter<
'static,
for<'cx> fn(&mut ModuleContext<'cx>) -> NeonResult<(&'static str, Handle<'cx, JsValue>)>,
>;
fn into_iter(self) -> Self::IntoIter {
crate::macro_internal::EXPORTS.into_iter()
}
}
pub fn registered() -> Exports {
Exports(())
}
#[test]
fn feature_matrix() {
use std::{env, process::Command};
const NODE_API_VERSIONS: &[&str] = &["napi-1", "napi-4", "napi-5", "napi-6", "napi-8"];
const FEATURES: &[&str] = &["external-buffers", "futures", "serde", "tokio", "tokio-rt"];
let cargo = env::var_os("CARGO").unwrap_or_else(|| "cargo".into());
for features in itertools::Itertools::powerset(FEATURES.iter()) {
for version in NODE_API_VERSIONS.iter().map(|f| f.to_string()) {
let features = features.iter().fold(version, |f, s| f + "," + s);
let status = Command::new(&cargo)
.args(["check", "-p", "neon", "--no-default-features", "--features"])
.arg(features)
.spawn()
.unwrap()
.wait()
.unwrap();
assert!(status.success());
}
}
}