Struct thread_object::Object [] [src]

pub struct Object<T> { /* fields omitted */ }

A multi-faced object.

An initial value is chosen upon creation. This value will be copied once the thread reads it for the first time. The value can be read and written, but will only be presented for the current thread. As such, it is "many-faced" meaning that different threads view different values.

Methods

impl<T> Object<T>
[src]

Create a new thread object with some initial value.

The specified value initial will be the value assigned when new threads read the object.

impl<T: Clone + Any> Object<T>
[src]

Read and/or modify the value associated with this thread.

This reads the object's value associated with the current thread, and initializes it if necessary. The mutable reference to the object is passed through the closure f and the return value of said closure is then returned.

The reason we use a closure is to prevent the programmer leaking the pointer to another thread, causing memory safety issues as the pointer is only valid in the current thread.

Replace the inner value.

This replaces the inner value with new and returns the old value.

Copy the inner value.

Trait Implementations

impl<T: Copy> Copy for Object<T>
[src]

impl<T: Clone> Clone for Object<T>
[src]

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

impl<T: Default> Default for Object<T>
[src]

Returns the "default value" for a type. Read more