#![cfg_attr(
feature = "nightly",
feature(
// using #[thread_local] works on #[no_std],
// and could be faster in some cases
thread_local,
)
)]
#![cfg_attr(
all(feature = "nightly", feature = "std"),
feature(
// used to make UniqueThreadId match std::thread::ThreadId
thread_id_value,
// used to quickly access the std thread id
current_thread_id,
)
)]
#![cfg_attr(feature = "nightly-docs", feature(doc_cfg))]
#![cfg_attr(not(feature = "std"), no_std)]
#![deny(
unsafe_op_in_unsafe_fn,
missing_docs,
clippy::std_instead_of_core,
clippy::std_instead_of_alloc,
clippy::alloc_instead_of_core,
clippy::undocumented_unsafe_blocks
)]
#![warn(clippy::multiple_unsafe_ops_per_block, clippy::pedantic)]
#![allow(
// stylistic
clippy::single_match_else,
)]
#[cfg(not(any(feature = "nightly", feature = "std")))]
compile_error!("The `threadid` crate requires at least one of the `nightly` or `std` features");
#[cfg(feature = "alloc")]
extern crate alloc;
use core::fmt::Debug;
use core::hash::Hash;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub use live::LiveThreadId;
pub use unique::UniqueThreadId;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub use self::std::StdThreadId;
#[macro_use]
mod utils;
#[macro_use]
mod locals;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub mod debug;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub mod live;
#[cfg(feature = "std")]
#[cfg_attr(feature = "nightly-docs", doc(cfg(feature = "std")))]
pub mod std;
pub mod unique;
pub unsafe trait IThreadId: Copy + Eq + Hash + Debug + sealed::Sealed {
fn current() -> Self;
}
mod sealed {
pub trait Sealed {}
impl Sealed for crate::UniqueThreadId {}
#[cfg(feature = "std")]
impl Sealed for crate::LiveThreadId {}
#[cfg(feature = "std")]
impl Sealed for crate::StdThreadId {}
#[cfg(feature = "std")]
impl Sealed for std::thread::ThreadId {}
}
#[inline]
#[must_use]
pub fn current<T: IThreadId>() -> T {
T::current()
}