Struct shareable::SharedObject
[−]
[src]
pub struct SharedObject<T> { /* fields omitted */ }
Shareable object data element.
Shares a read only object between multiple instances using an AtomicPtr and a small sping lock.
Examples
use std::sync::mpsc; use std::thread; use shareable::SharedObject; let value1 = SharedObject::new(String::from("abc")); let value2 = value1.clone(); let (tx, rx) = mpsc::channel(); let thread = thread::spawn(move || { rx.recv(); assert_eq!(value2.get().as_str(), "xyz"); }); value1.set(String::from("xyz")); tx.send(()); thread.join().unwrap();
Methods
impl<T> SharedObject<T>
[src]
fn new(value: T) -> SharedObject<T>
Construct a new instance of the object.
fn set(&self, value: T)
Set the value of the object.
fn get(&self) -> Box<Arc<T>>
Returns the value of the object.
Trait Implementations
impl<T: Clone> Clone for SharedObject<T>
[src]
fn clone(&self) -> SharedObject<T>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more