Struct NoRefParSlice

Source
pub struct NoRefParSlice;
Expand description

Utility struct for contructors for slices that allow unsynchronized access to their elements through UnsafeNoRefIndex and UnsafeNoRefChunkIndex.

Implementations§

Source§

impl NoRefParSlice

Source

pub fn new<T: Default + Send + Sync>( len: usize, ) -> impl UnsafeNoRefIndex<T> + ParCollection<Box<[T]>>

Constructs a new slice with len elements, each initialized to T::default, that allows unsynchronized access to its elements through UnsafeNoRefIndex and that can be converted into a boxed slice.

§Examples
let data_race_slice = NoRefParSlice::new(4);

unsafe {
    data_race_slice.set(0, 42);
}

assert_eq!(data_race_slice.into().as_ref(), &[42, 0, 0, 0]);
Source

pub fn with_value<T: Clone + Send + Sync>( value: T, len: usize, ) -> impl UnsafeNoRefIndex<T> + ParCollection<Box<[T]>>

Constructs a new slice with len elements, each initialized to value, that allows unsynchronized access to its elements through UnsafeNoRefIndex and that can be converted into a boxed slice.

§Examples
let data_race_slice = NoRefParSlice::with_value(69, 4);

unsafe {
    data_race_slice.set(0, 42);
}

assert_eq!(data_race_slice.into().as_ref(), &[42, 69, 69, 69]);
Source

pub fn with_closure<T: Send + Sync>( closure: impl FnMut(usize) -> T, len: usize, ) -> impl UnsafeNoRefIndex<T> + ParCollection<Box<[T]>>

Constructs a new slice with len elements, each initialized to the return value of closure called with the index of the element to generate as an usize, that allows unsynchronized access to its elements through UnsafeNoRefIndex and that can be converted into a boxed slice.

§Examples
let data_race_slice = NoRefParSlice::with_closure(|i| i, 4);

unsafe {
    data_race_slice.set(0, 42);
}

assert_eq!(data_race_slice.into().as_ref(), &[42, 1, 2, 3]);
Source

pub fn new_chunks<T: Default + Send + Sync>( len: usize, chunk_size: usize, ) -> impl UnsafeNoRefChunkIndex<T> + ParCollection<Box<[T]>>

Constructs a new slice with len elements, each initialized to T::default, that allows unsynchronized access to chunks of chunk_size of its elements through UnsafeNoRefChunkIndex and that can be converted into a boxed slice.

§Examples
let data_race_slice = NoRefParSlice::new_chunks(4, 2);

unsafe {
    data_race_slice.set(0, &[42, 0]);
}

assert_eq!(data_race_slice.into().as_ref(), &[42, 0, 0, 0]);
Source

pub fn chunks_with_value<T: Clone + Send + Sync>( value: T, len: usize, chunk_size: usize, ) -> impl UnsafeNoRefChunkIndex<T> + ParCollection<Box<[T]>>

Constructs a new slice with len elements, each initialized to value, that allows unsynchronized access to chunks of chunk_size of its elements through UnsafeNoRefChunkIndex and that can be converted into a boxed slice.

§Examples
let data_race_slice = NoRefParSlice::chunks_with_value(69, 4, 2);

unsafe {
    data_race_slice.set(0, &[42, 69]);
}

assert_eq!(data_race_slice.into().as_ref(), &[42, 69, 69, 69]);
Source

pub fn chunks_with_closure<T: Send + Sync>( closure: impl FnMut(usize) -> T, len: usize, chunk_size: usize, ) -> impl UnsafeNoRefChunkIndex<T> + ParCollection<Box<[T]>>

Constructs a new slice with len elements, each initialized to the return value of closure called with the index of the element to generate as an usize, that allows unsynchronized access to chunks of chunk_size of its elements through UnsafeNoRefChunkIndex and that can be converted into a boxed slice.

§Examples
let data_race_slice = NoRefParSlice::chunks_with_closure(|i| i, 4, 2);

unsafe {
    data_race_slice.set(0, &[42, 1]);
}

assert_eq!(data_race_slice.into().as_ref(), &[42, 1, 2, 3]);

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.