diff --git a/src/basics.md b/src/basics.md index 1fb4b78..e9c185d 100644 --- a/src/basics.md +++ b/src/basics.md @@ -19,6 +19,7 @@ | [Calculate the SHA-256 digest of a file][ex-sha-digest] | [![ring-badge]][ring] [![data-encoding-badge]][data-encoding] | [![cat-cryptography-badge]][cat-cryptography] | | [Define and operate on a type represented as a bitfield][ex-bitflags] | [![bitflags-badge]][bitflags] | [![cat-no-std-badge]][cat-no-std] | | [Access a file randomly using a memory map][ex-random-file-access] | [![memmap-badge]][memmap] | [![cat-filesystem-badge]][cat-filesystem] | +| [Check number of logical cpu cores][ex-check-cpu-cores] | [![num_cpus-badge]][num_cpus] | [![cat-hardware-support-badge]][cat-hardware-support] | [ex-std-read-lines]: #ex-std-read-lines @@ -847,6 +848,22 @@ fn run() -> Result<()> { # quick_main!(run); ``` +[ex-check-cpu-cores]: #ex-check-cpu-cores + +## Check number of logical cpu cores + +[![num_cpus-badge]][num_cpus] [![cat-hardware-support-badge]][cat-hardware-support] + +Shows the number of logical cpu cores in current machine using [`num_cpus::get`]. + +```rust +extern crate num_cpus; + +fn main() { + println!("Number of logical cores is {}", num_cpus::get()); +} +``` + {{#include links.md}} @@ -862,6 +879,7 @@ fn run() -> Result<()> { [`Lines`]: https://doc.rust-lang.org/std/io/struct.Lines.html [`Read`]: https://doc.rust-lang.org/std/io/trait.Read.html [`Normal`]: https://doc.rust-lang.org/rand/rand/distributions/normal/struct.Normal.html +[`num_cpus::get`]: https://docs.rs/num_cpus/*/num_cpus/fn.get.html [`IndependentSample::ind_sample`]: https://doc.rust-lang.org/rand/rand/distributions/trait.IndependentSample.html#tymethod.ind_sample [`Rng::gen_range`]: https://doc.rust-lang.org/rand/rand/trait.Rng.html#method.gen_range [`Regex::captures_iter`]: https://doc.rust-lang.org/regex/regex/struct.Regex.html#method.captures_iter diff --git a/src/intro.md b/src/intro.md index 60b2de1..591210d 100644 --- a/src/intro.md +++ b/src/intro.md @@ -37,6 +37,7 @@ community. It needs and welcomes help. For details see | [Calculate the SHA-256 digest of a file][ex-sha-digest] | [![ring-badge]][ring] [![data-encoding-badge]][data-encoding] | [![cat-cryptography-badge]][cat-cryptography] | | [Define and operate on a type represented as a bitfield][ex-bitflags] | [![bitflags-badge]][bitflags] | [![cat-no-std-badge]][cat-no-std] | | [Access a file randomly using a memory map][ex-random-file-access] | [![memmap-badge]][memmap] | [![cat-filesystem-badge]][cat-filesystem] | +| [Check number of logical cpu cores][ex-check-cpu-cores] | [![num_cpus-badge]][num_cpus] | [![cat-hardware-support-badge]][cat-hardware-support] | ## [Encoding](encoding.html) @@ -136,6 +137,7 @@ community. It needs and welcomes help. For details see [ex-byteorder-le]: basics.html#ex-byteorder-le [ex-cc-static-bundled]: build_tools.html#ex-cc-static-bundled [ex-check-broken-links]: net.html#ex-check-broken-links +[ex-check-cpu-cores]: basics.html#ex-check-cpu-cores [ex-clap-basic]: app.html#ex-clap-basic [ex-crossbeam-spawn]: concurrency.html#ex-crossbeam-spawn [ex-csv-serde]: encoding.html#ex-csv-serde diff --git a/src/links.md b/src/links.md index 34f1b6a..a61278a 100644 --- a/src/links.md +++ b/src/links.md @@ -25,6 +25,8 @@ Keep lines sorted. [cat-encoding]: https://crates.io/categories/encoding [cat-filesystem-badge]: https://badge-cache.kominick.com/badge/filesystem--x.svg?style=social [cat-filesystem]: https://crates.io/categories/filesystem +[cat-hardware-support-badge]: https://badge-cache.kominick.com/badge/hardware_support--x.svg?style=social +[cat-hardware-support]: https://crates.io/categories/hardware-support [cat-net-badge]: https://badge-cache.kominick.com/badge/net--x.svg?style=social [cat-net]: https://crates.io/categories/network-programming [cat-no-std-badge]: https://badge-cache.kominick.com/badge/no_std--x.svg?style=social