pub struct ThreadId(/* private fields */);Expand description
A unique identifier for a running thread.
A ThreadId is an opaque object that uniquely identifies each thread
created during the lifetime of a process. ThreadIds are guaranteed not to
be reused, even when a thread terminates. ThreadIds are under the control
of Rust’s standard library and there may not be any relationship between
ThreadId and the underlying platform’s notion of a thread identifier –
the two concepts cannot, therefore, be used interchangeably. A ThreadId
can be retrieved from the id method on a Thread.
§Examples
use std::thread;
let other_thread = thread::spawn(|| {
thread::current().id()
});
let other_thread_id = other_thread.join().unwrap();
assert!(thread::current().id() != other_thread_id);Implementations§
source§impl ThreadId
impl ThreadId
sourcepub fn as_u64(&self) -> NonZero<u64>
🔬This is a nightly-only experimental API. (thread_id_value)
pub fn as_u64(&self) -> NonZero<u64>
thread_id_value)This returns a numeric identifier for the thread identified by this
ThreadId.
As noted in the documentation for the type itself, it is essentially an opaque ID, but is guaranteed to be unique for each thread. The returned value is entirely opaque – only equality testing is stable. Note that it is not guaranteed which values new threads will return, and this may change across Rust versions.
Trait Implementations§
1.19.0 · source§impl PartialEq for ThreadId
impl PartialEq for ThreadId
impl Copy for ThreadId
impl Eq for ThreadId
impl StructuralPartialEq for ThreadId
Auto Trait Implementations§
impl Freeze for ThreadId
impl RefUnwindSafe for ThreadId
impl Send for ThreadId
impl Sync for ThreadId
impl Unpin for ThreadId
impl UnwindSafe for ThreadId
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more