Struct ParSlice

Source
pub struct ParSlice;
Expand description

Utility struct for contructors for slices that allow unsynchronized access to their elements through UnsafeIndex and UnsafeChunkIndex.

Implementations§

Source§

impl ParSlice

Source

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

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

§Examples
let unsafe_slice = ParSlice::new(4);

unsafe {
    *unsafe_slice.get_mut(0) = 42;
}

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

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

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

§Examples
let unsafe_slice = ParSlice::with_value(69, 4);

unsafe {
    *unsafe_slice.get_mut(0) = 42;
}

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

pub fn with_closure<T: Send + Sync>( closure: impl FnMut(usize) -> T, len: usize, ) -> impl UnsafeIndex<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 UnsafeIndex and that can be converted into a boxed slice.

§Examples
let unsafe_slice = ParSlice::with_closure(|i| i, 4);

unsafe {
    *unsafe_slice.get_mut(0) = 42;
}

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

pub fn new_chunks<T: Default + Send + Sync>( len: usize, chunk_size: usize, ) -> impl UnsafeChunkIndex<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 UnsafeChunkIndex and that can be converted into a boxed slice.

§Examples
let unsafe_slice = ParSlice::new_chunks(4, 2);

unsafe {
    unsafe_slice.get_mut(0)[0] = 42;
}

assert_eq!(unsafe_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 UnsafeChunkIndex<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 UnsafeChunkIndex and that can be converted into a boxed slice.

§Examples
let unsafe_slice = ParSlice::chunks_with_value(69, 4, 2);

unsafe {
    unsafe_slice.get_mut(0)[0] = 42;
}

assert_eq!(unsafe_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 UnsafeChunkIndex<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 UnsafeChunkIndex and that can be converted into a boxed slice.

§Examples
let unsafe_slice = ParSlice::chunks_with_closure(|i| i, 4, 2);

unsafe {
    unsafe_slice.get_mut(0)[0] = 42;
}

assert_eq!(unsafe_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.