diff --git a/Cargo.lock b/Cargo.lock index 46c3a4b..7dd3d4d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -11,10 +11,43 @@ dependencies = [ "memchr", ] +[[package]] +name = "bitflags" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf4b9d6a944f767f8e5e0db018570623c85f3d925ac718db4e06d0187adb21c1" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "convert_case" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec182b0ca2f35d8fc196cf3404988fd8b8c739a4d270ff118a398feb0cbec1ca" +dependencies = [ + "unicode-segmentation", +] + +[[package]] +name = "ctor" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ad291aa74992b9b7a7e88c38acbbf6ad7e107f1d90ee8775b7bc1fc3394f485c" +dependencies = [ + "quote", + "syn", +] + [[package]] name = "jlabel" version = "0.1.4" dependencies = [ + "napi", + "napi-derive", "serde", "thiserror", ] @@ -30,12 +63,79 @@ dependencies = [ "thiserror", ] +[[package]] +name = "libloading" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c2a198fb6b0eada2a8df47933734e6d35d350665a33a3593d7164fa52c75c19" +dependencies = [ + "cfg-if", + "windows-targets", +] + [[package]] name = "memchr" version = "2.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" +[[package]] +name = "napi" +version = "2.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4ca998356d8ff9fba7a070dae4508a2298439c98c9f3bc9c07669538b999e8f" +dependencies = [ + "bitflags", + "ctor", + "napi-derive", + "napi-sys", + "once_cell", +] + +[[package]] +name = "napi-derive" +version = "2.16.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b138cecf1141ae0ff5d62f4aa0e2f269aec339f66070f346ba6fb4279f1fc178" +dependencies = [ + "cfg-if", + "convert_case", + "napi-derive-backend", + "proc-macro2", + "quote", + "syn", +] + +[[package]] +name = "napi-derive-backend" +version = "1.0.63" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce5126b64f6ad9e28e30e6d15213dd378626b38f556454afebc42f7f02a90902" +dependencies = [ + "convert_case", + "once_cell", + "proc-macro2", + "quote", + "regex", + "semver", + "syn", +] + +[[package]] +name = "napi-sys" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2503fa6af34dc83fb74888df8b22afe933b58d37daf7d80424b1c60c68196b8b" +dependencies = [ + "libloading", +] + +[[package]] +name = "once_cell" +version = "1.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92" + [[package]] name = "proc-macro2" version = "1.0.78" @@ -54,6 +154,18 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "regex" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + [[package]] name = "regex-automata" version = "0.4.5" @@ -71,6 +183,12 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c08c74e62047bb2de4ff487b251e4a92e24f48745648451635cec7d591162d9f" +[[package]] +name = "semver" +version = "1.0.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" + [[package]] name = "serde" version = "1.0.197" @@ -127,3 +245,66 @@ name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" + +[[package]] +name = "unicode-segmentation" +version = "1.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4c87d22b6e3f4a18d4d40ef354e97c90fcb14dd91d7dc0aa9d8a1172ebf7202" + +[[package]] +name = "windows-targets" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" diff --git a/crates/jlabel/Cargo.toml b/crates/jlabel/Cargo.toml index c54a213..6888e44 100644 --- a/crates/jlabel/Cargo.toml +++ b/crates/jlabel/Cargo.toml @@ -18,8 +18,11 @@ rustdoc-args = ["--cfg", "docsrs"] [features] serde = ["dep:serde"] +napi = ["dep:napi", "dep:napi-derive"] [dependencies] thiserror.workspace = true serde = { version = "1", features = ["derive"], optional = true } +napi = { version = "2", optional = true } +napi-derive = { version = "2", optional = true } diff --git a/crates/jlabel/src/fullcontext_label.rs b/crates/jlabel/src/fullcontext_label.rs index c36512f..b1de41a 100644 --- a/crates/jlabel/src/fullcontext_label.rs +++ b/crates/jlabel/src/fullcontext_label.rs @@ -1,3 +1,5 @@ +#[cfg(feature = "napi")] +use napi_derive::napi; #[cfg(feature = "serde")] use serde::{Deserialize, Serialize}; @@ -5,6 +7,7 @@ use serde::{Deserialize, Serialize}; /// /// The parser from str, and the serializer to String are both implemented. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Label { /// Phoneme @@ -35,6 +38,7 @@ pub struct Label { /// `Phoneme` field of full-context label. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Phoneme { /// P1: the phoneme identity before the previous phoneme @@ -51,6 +55,7 @@ pub struct Phoneme { /// `Mora` field of full-context label (`A` field). #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Mora { /// A1: the difference between accent type and position of the current mora identity @@ -63,6 +68,7 @@ pub struct Mora { /// `Word` field of full-context label (`B`, `C`, and `D` field). #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Word { /// B1/C1/D1: pos (part-of-speech) of the word @@ -77,6 +83,7 @@ pub struct Word { /// /// F4 is undefined. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct AccentPhraseCurrent { /// F1: the number of moras in the current accent phrase @@ -99,6 +106,7 @@ pub struct AccentPhraseCurrent { /// /// E4/G4 is undefined. #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct AccentPhrasePrevNext { /// E1/G1: the number of moras in the accent phrase @@ -120,6 +128,7 @@ pub struct AccentPhrasePrevNext { /// `BreathGroup` field of full-context label for current breath group (`I` field). #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BreathGroupCurrent { /// I1: the number of accent phrases in the current breath group @@ -142,6 +151,7 @@ pub struct BreathGroupCurrent { /// `BreathGroup` field of full-context label for previous or next breath group (`H` and `J` field). #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct BreathGroupPrevNext { /// H1/J1: the number of accent phrases in the breath group @@ -152,6 +162,7 @@ pub struct BreathGroupPrevNext { /// `Utterance` field of full-context label (`K` field). #[derive(Debug, Clone, PartialEq, Eq)] +#[cfg_attr(feature = "napi", napi(object))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct Utterance { /// K1: the number of breath groups in this utterance