Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 7 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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<Vec<CoreId>> {
get_core_ids_helper()
Expand All @@ -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,
}
Expand Down