Struct ste::Tag[][src]

#[repr(transparent)]pub struct Tag(_);

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]

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]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.