Struct ste::Tag [−][src]
A tag associated with a thread. Threads which are executed with Thread support tagging.
You must ensure that any thread trying to use values first is checked with the current tag through Tag::ensure_on_thread. This includes everything which poses a potential thread safety risk.
If that is done, you can safely implement Send for the type.
Examples
struct Foo { tag: ste::Tag, data: *mut (), } impl Foo { fn new() -> Self { Self { tag: ste::Tag::current_thread(), data: std::ptr::null_mut(), } } fn say_hello(&self) { self.tag.ensure_on_thread(); println!("Hello from Foo"); } } // Safety: the structure is explicitly tagged with the thread that created // it, and we ensure everywhere where racy access might otherwise happen // that it is on the creating thread. unsafe impl Send for Foo {} let thread = ste::Thread::new()?; let foo = thread.submit(|| Foo::new())?; assert!(!foo.tag.is_on_thread()); foo.say_hello(); // <- oops, this panics thread.join()?;
Implementations
impl Tag
[src]
pub fn current_thread() -> Self
[src]
Get the tag associated with the current thread.
See Tag documentation for how to use.
Panics
Panics if not running on a tagged thread. Tagged threads are the ones created with Thread.
pub fn ensure_on_thread(&self)
[src]
Ensure that the tag is currently executing on the thread that created it.
See Tag documentation for how to use.
Panics
Panics if not running on a tagged thread. Tagged threads are the ones created with Thread.
Also panics unless called on the same thread that the tag was created on.
pub fn is_on_thread(&self) -> bool
[src]
Test if we’re currently on the tagged thread.
See Tag documentation for how to use.
Trait Implementations
impl Clone for Tag
[src]
impl Copy for Tag
[src]
impl Debug for Tag
[src]
impl Eq for Tag
[src]
impl Hash for Tag
[src]
fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl PartialEq<Tag> for Tag
[src]
impl StructuralEq for Tag
[src]
impl StructuralPartialEq for Tag
[src]
Auto Trait Implementations
impl RefUnwindSafe for Tag
impl Send for Tag
impl Sync for Tag
impl Unpin for Tag
impl UnwindSafe for Tag
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
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>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,