Struct std::thread::ThreadId
pub struct ThreadId(_);
A unique identifier for a running thread.
A ThreadId
is an opaque object that has a unique value for each thread that creates one. ThreadId
s are not guaranteed to correspond to a thread’s system-designated identifier. 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
impl ThreadId
pub fn as_u64(&self) -> NonZeroU64
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
impl Clone for ThreadId
fn clone(&self) -> ThreadId
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Debug for ThreadId
fn fmt(&self, f: &mut Formatter<'_>) -> Result
Formats the value using the given formatter. Read more
impl Hash for ThreadId
fn hash<__H: Hasher>(&self, state: &mut __H)
impl PartialEq<ThreadId> for ThreadId
fn eq(&self, other: &ThreadId) -> bool
This method tests for self
and other
values to be equal, and is used by ==
. Read more
fn ne(&self, other: &ThreadId) -> bool
This method tests for !=
.
impl Copy for ThreadId
impl Eq for ThreadId
impl StructuralEq for ThreadId
impl StructuralPartialEq for ThreadId
Auto Trait Implementations
impl RefUnwindSafe for ThreadId
impl Send for ThreadId
impl Sync for ThreadId
impl Unpin for ThreadId
impl UnwindSafe for ThreadId
Blanket Implementations
impl<T> From<T> for T
pub fn from(t: T) -> T
Performs the conversion.
pub fn into(self) -> U
Performs the conversion.
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
toowned_clone_into
#41263)recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
Performs the conversion.
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
Performs the conversion.
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/thread/struct.ThreadId.html