Struct ThreadId

pub struct ThreadId(pub(in ::thread::id) NonZero<u64>);

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);

Fields

0: NonZero<u64>

Implementations

impl ThreadId

fn new() -> ThreadId
fn from_u64(v: u64) -> Option<ThreadId>
fn as_u64(&self) -> NonZero<u64>

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

impl Copy for ThreadId

impl Debug for ThreadId

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl Eq for ThreadId

fn assert_fields_are_eq(&self)

impl Hash for ThreadId

fn hash<__H: Hasher>(&self, state: &mut __H)

impl PartialEq for ThreadId

fn eq(&self, other: &ThreadId) -> bool

impl StructuralPartialEq for ThreadId

impl TrivialClone 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 UnsafeUnpin for ThreadId

impl UnwindSafe for ThreadId

Blanket Implementations

impl<T> Any for ThreadId where T: 'static + ?Sized,

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for ThreadId where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for ThreadId where T: ?Sized,

fn borrow_mut(&mut self) -> &mut T

impl<T> CloneToUninit for ThreadId where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for ThreadId

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> Printable for ThreadId where T: Copy + Debug,

impl<T> SizeHint for ThreadId where T: ?Sized,

fn lower_bound(&self) -> usize
fn upper_bound(&self) -> Option<usize>

impl<T> SizedTypeProperties for ThreadId

impl<T> ToOwned for ThreadId where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for ThreadId where U: From<T>,

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

impl<T, U> TryFrom<U> for ThreadId where U: Into<T>,

type Error = Infallible;
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

impl<T, U> TryInto<U> for ThreadId where U: TryFrom<T>,

type Error = <U as TryFrom<T>>::Error;
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>