7 stable releases (3 major)

Uses old Rust 2015

4.0.0 Mar 24, 2021
3.3.0 Mar 23, 2018
3.2.0 Jun 26, 2017
3.1.0 May 13, 2017
1.0.0 Mar 13, 2016

#14 in #thread

Download history 48006/week @ 2021-10-08 54141/week @ 2021-10-15 48007/week @ 2021-10-22 41032/week @ 2021-10-29 31554/week @ 2021-11-05 30635/week @ 2021-11-12 30185/week @ 2021-11-19 32887/week @ 2021-11-26 38816/week @ 2021-12-03 40073/week @ 2021-12-10 34279/week @ 2021-12-17 21746/week @ 2021-12-24 31013/week @ 2021-12-31 36427/week @ 2022-01-07 39184/week @ 2022-01-14 47788/week @ 2022-01-21

157,712 downloads per month
Used in 845 crates (25 directly)

MIT/Apache

9KB

Thread-ID

Get a unique ID for the current thread in Rust.

Build Status Build Status Crates.io version Documentation

For diagnostics and debugging it can often be useful to get an ID that is different for every thread. Until Rust 1.14, the standard library did not expose a way to do that, hence this crate.

Example

use std::thread;
use thread_id;

let handle = thread::spawn(move || {
    println!("spawned thread has id {}", thread_id::get());
});

println!("main thread has id {}", thread_id::get());

handle.join().unwrap();

This will print two different numbers.

License

Thread-ID is licensed under either the Apache 2.0 license, or the MIT license, at your option. It may be used in free software as well as closed-source applications, both for commercial and non-commercial use under the conditions given in the license.

Contributing

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache 2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~63KB