diff --git a/Cargo.toml b/Cargo.toml index 37c294b..77b65f2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,10 +12,12 @@ documentation = "https://docs.rs/instant-segment" [features] __test_data = ["test-cases"] test-cases = [] +with-serde = ["serde", "ahash/serde", "smartstring/serde"] [dependencies] ahash = "0.7.0" smartstring = "0.2.5" +serde = { version = "1.0.123", features = ["derive"], optional = true } [dev-dependencies] bencher = "0.1.5" diff --git a/src/lib.rs b/src/lib.rs index 73d86f4..df22809 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,6 +1,8 @@ use std::ops::{Index, Range}; use std::str; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; use smartstring::alias::String; #[cfg(feature = "test-cases")] @@ -9,6 +11,7 @@ pub mod test_cases; pub mod test_data; /// Central data structure used to calculate word probabilities +#[cfg_attr(feature = "with-serde", derive(Deserialize, Serialize))] pub struct Segmenter { unigrams: HashMap, bigrams: HashMap<(String, String), f64>,