10 stable releases (3 major)

Uses old Rust 2015

4.2.1 Oct 16, 2023
4.1.0 May 15, 2023
4.0.0 Mar 24, 2021
3.3.0 Mar 23, 2018
1.0.0 Mar 13, 2016

#55 in Debugging

Download history 36822/week @ 2023-12-23 51079/week @ 2023-12-30 63733/week @ 2024-01-06 66821/week @ 2024-01-13 71130/week @ 2024-01-20 75254/week @ 2024-01-27 78583/week @ 2024-02-03 71467/week @ 2024-02-10 72608/week @ 2024-02-17 76746/week @ 2024-02-24 83342/week @ 2024-03-02 81459/week @ 2024-03-09 82407/week @ 2024-03-16 79648/week @ 2024-03-23 79704/week @ 2024-03-30 70676/week @ 2024-04-06

323,794 downloads per month
Used in 1,000 crates (35 directly)

MIT/Apache

10KB
79 lines

Thread-ID

Get a unique ID for the current thread in Rust.

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

~215KB