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
impl NoRefParSlice
Sourcepub fn new<T: Default + Send + Sync>(
len: usize,
) -> impl UnsafeNoRefIndex<T> + ParCollection<Box<[T]>>
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]);Sourcepub fn with_value<T: Clone + Send + Sync>(
value: T,
len: usize,
) -> impl UnsafeNoRefIndex<T> + ParCollection<Box<[T]>>
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]);Sourcepub fn with_closure<T: Send + Sync>(
closure: impl FnMut(usize) -> T,
len: usize,
) -> impl UnsafeNoRefIndex<T> + ParCollection<Box<[T]>>
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]);Sourcepub fn new_chunks<T: Default + Send + Sync>(
len: usize,
chunk_size: usize,
) -> impl UnsafeNoRefChunkIndex<T> + ParCollection<Box<[T]>>
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]);Sourcepub fn chunks_with_value<T: Clone + Send + Sync>(
value: T,
len: usize,
chunk_size: usize,
) -> impl UnsafeNoRefChunkIndex<T> + ParCollection<Box<[T]>>
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]);Sourcepub fn chunks_with_closure<T: Send + Sync>(
closure: impl FnMut(usize) -> T,
len: usize,
chunk_size: usize,
) -> impl UnsafeNoRefChunkIndex<T> + ParCollection<Box<[T]>>
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]);