diff --git a/Cargo.toml b/Cargo.toml index cbda8e0..f25d111 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,6 +13,11 @@ categories = ["os"] [dependencies] num_cpus = "^1.14.0" +serde = { version = "1.0", optional = true, features = ["derive"] } + +[features] +default = [] +serde = ["dep:serde"] [target.'cfg(any(target_os = "android", target_os = "linux", target_os = "macos", target_os = "freebsd", target_os = "netbsd"))'.dependencies] libc = "^0.2.30" diff --git a/src/lib.rs b/src/lib.rs index cf8532f..90bf9be 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -28,6 +28,11 @@ //! } //! ``` +#[cfg(feature = "serde")] +extern crate serde; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + #[cfg(any( target_os = "android", target_os = "linux", @@ -41,7 +46,7 @@ extern crate libc; extern crate num_cpus; /// This function tries to retrieve information -/// on all the "cores" on which the current thread +/// on all the "cores" on which the current thread /// is allowed to run. pub fn get_core_ids() -> Option> { get_core_ids_helper() @@ -60,6 +65,7 @@ pub fn set_for_current(core_id: CoreId) -> bool { /// This represents a CPU core. #[repr(transparent)] #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct CoreId { pub id: usize, }