sync_cell_slice

Trait SyncSlice

Source
pub trait SyncSlice<T> {
    // Required method
    fn as_sync_slice(&mut self) -> &[SyncCell<T>];
}
Expand description

Extension trait turning a &mut [T] into a &[SyncCell<T>].

The result Sync if T is Sync.

Required Methods§

Source

fn as_sync_slice(&mut self) -> &[SyncCell<T>]

Returns a &[SyncCell<T>] from a &mut [T].

§Examples
use sync_cell_slice::SyncSlice;

let mut v = vec![1, 2, 3, 4];
// s can be used to write to v from multiple threads
let s = v.as_sync_slice();

std::thread::scope(|scope| {
    scope.spawn(|| {
        unsafe { s[0].set(5) };
    });
    scope.spawn(|| {
        unsafe { s[1].set(10) };
    });
});

Implementations on Foreign Types§

Source§

impl<T> SyncSlice<T> for [T]

Source§

fn as_sync_slice(&mut self) -> &[SyncCell<T>]

Implementors§