pub trait AllocSliceExt: AllocSlice + AllocExt {
// Provided methods
fn alloc_slice_filled<T>(
&self,
len: usize,
n: u8,
) -> Result<NonNull<[T]>, AllocError> { ... }
fn alloc_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
len: usize,
pattern: F,
) -> Result<NonNull<[T]>, AllocError> { ... }
unsafe fn grow_slice_filled<T>(
&self,
slice: NonNull<[T]>,
new_len: usize,
n: u8,
) -> Result<NonNull<[T]>, AllocError> { ... }
unsafe fn grow_raw_slice_filled<T>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
n: u8,
) -> Result<NonNull<T>, AllocError> { ... }
unsafe fn grow_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
slice: NonNull<[T]>,
new_len: usize,
pattern: F,
) -> Result<NonNull<[T]>, AllocError> { ... }
unsafe fn grow_raw_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
pattern: F,
) -> Result<NonNull<T>, AllocError> { ... }
unsafe fn realloc_slice_filled<T>(
&self,
slice: NonNull<[T]>,
new_len: usize,
n: u8,
) -> Result<NonNull<[T]>, AllocError> { ... }
unsafe fn realloc_raw_slice_filled<T>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
n: u8,
) -> Result<NonNull<T>, AllocError> { ... }
unsafe fn realloc_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
slice: NonNull<[T]>,
new_len: usize,
pattern: F,
) -> Result<NonNull<[T]>, AllocError> { ... }
unsafe fn realloc_raw_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
pattern: F,
) -> Result<NonNull<T>, AllocError> { ... }
}
Expand description
Slice-specific extension methods for AllocExt
, providing
extended convenient functions for slice allocator operations.
Provided Methods§
Sourcefn alloc_slice_filled<T>(
&self,
len: usize,
n: u8,
) -> Result<NonNull<[T]>, AllocError>
fn alloc_slice_filled<T>( &self, len: usize, n: u8, ) -> Result<NonNull<[T]>, AllocError>
Attempts to allocate a block of memory for len
instances of T
, filled with bytes
initialized to n
.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed layout is invalid.AllocError::ZeroSizedLayout
if the computed slice has a size of zero.
Sourcefn alloc_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
len: usize,
pattern: F,
) -> Result<NonNull<[T]>, AllocError>
fn alloc_slice_patterned<T, F: Fn(usize) -> u8 + Clone>( &self, len: usize, pattern: F, ) -> Result<NonNull<[T]>, AllocError>
Attempts to allocate a block of memory for len
instances of T
and
fill it by calling pattern(i)
for each byte index i
.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed layout is invalid.AllocError::ZeroSizedLayout
if the computed slice has a size of zero.
Sourceunsafe fn grow_slice_filled<T>(
&self,
slice: NonNull<[T]>,
new_len: usize,
n: u8,
) -> Result<NonNull<[T]>, AllocError>
unsafe fn grow_slice_filled<T>( &self, slice: NonNull<[T]>, new_len: usize, n: u8, ) -> Result<NonNull<[T]>, AllocError>
Grows a slice to a new length, filling any newly allocated bytes with n
.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed slice would be zero-sized.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.AllocError::GrowSmallerNewLayout
ifnew_len < slice.len()
.
§Safety
slice
must point to a slice allocated using this allocator.
Sourceunsafe fn grow_raw_slice_filled<T>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
n: u8,
) -> Result<NonNull<T>, AllocError>
unsafe fn grow_raw_slice_filled<T>( &self, ptr: NonNull<T>, len: usize, new_len: usize, n: u8, ) -> Result<NonNull<T>, AllocError>
Grows a slice to a new length given the pointer to its first element, current length, and
requested length, filling any newly allocated bytes with n
.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed layout is invalid.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.AllocError::GrowSmallerNewLayout
ifnew_len < len
.
§Safety
ptr
must point to a slice allocated using this allocator.len
must describe exactly the number of elements in that slice.
Sourceunsafe fn grow_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
slice: NonNull<[T]>,
new_len: usize,
pattern: F,
) -> Result<NonNull<[T]>, AllocError>
unsafe fn grow_slice_patterned<T, F: Fn(usize) -> u8 + Clone>( &self, slice: NonNull<[T]>, new_len: usize, pattern: F, ) -> Result<NonNull<[T]>, AllocError>
Grows a slice to a new length, filling any newly allocated bytes by calling pattern(i)
for each new byte index i
.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed slice would be zero-sized.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.AllocError::GrowSmallerNewLayout
ifnew_len < slice.len()
.
§Safety
slice
must point to a slice allocated using this allocator.
Sourceunsafe fn grow_raw_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
pattern: F,
) -> Result<NonNull<T>, AllocError>
unsafe fn grow_raw_slice_patterned<T, F: Fn(usize) -> u8 + Clone>( &self, ptr: NonNull<T>, len: usize, new_len: usize, pattern: F, ) -> Result<NonNull<T>, AllocError>
Grows a slice to a new length given the pointer to its first element, current length, and
requested length, filling any newly allocated bytes by calling pattern(i)
for each new
byte index i
.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed layout is invalid.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.AllocError::GrowSmallerNewLayout
ifnew_len < len
.
§Safety
ptr
must point to a slice allocated using this allocator.len
must describe exactly the number of elements in that slice.
Sourceunsafe fn realloc_slice_filled<T>(
&self,
slice: NonNull<[T]>,
new_len: usize,
n: u8,
) -> Result<NonNull<[T]>, AllocError>
unsafe fn realloc_slice_filled<T>( &self, slice: NonNull<[T]>, new_len: usize, n: u8, ) -> Result<NonNull<[T]>, AllocError>
Reallocates a slice to a new length, filling any newly allocated bytes with n
.
On grow, preserves all existing elements and truncates to new_len
elements on shrink.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed slice would be zero-sized.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.
§Safety
slice
must point to a slice allocated using this allocator.
Sourceunsafe fn realloc_raw_slice_filled<T>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
n: u8,
) -> Result<NonNull<T>, AllocError>
unsafe fn realloc_raw_slice_filled<T>( &self, ptr: NonNull<T>, len: usize, new_len: usize, n: u8, ) -> Result<NonNull<T>, AllocError>
Reallocates a slice to a new length given the pointer to its first element, current length,
and requested length, filling any newly allocated bytes with n
.
On grow, preserves all existing elements and truncates to new_len
elements on shrink.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed slice would be zero-sized.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.
§Safety
ptr
must point to a slice allocated using this allocator.len
must describe exactly the number of elements in that slice.
Sourceunsafe fn realloc_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
slice: NonNull<[T]>,
new_len: usize,
pattern: F,
) -> Result<NonNull<[T]>, AllocError>
unsafe fn realloc_slice_patterned<T, F: Fn(usize) -> u8 + Clone>( &self, slice: NonNull<[T]>, new_len: usize, pattern: F, ) -> Result<NonNull<[T]>, AllocError>
Reallocates a slice to a new length, filling any newly allocated bytes by calling
pattern(i)
for each new byte index i
.
On grow, preserves all existing elements and truncates to new_len
elements on shrink.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed slice would be zero-sized.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.
§Safety
slice
must point to a slice allocated using this allocator.
Sourceunsafe fn realloc_raw_slice_patterned<T, F: Fn(usize) -> u8 + Clone>(
&self,
ptr: NonNull<T>,
len: usize,
new_len: usize,
pattern: F,
) -> Result<NonNull<T>, AllocError>
unsafe fn realloc_raw_slice_patterned<T, F: Fn(usize) -> u8 + Clone>( &self, ptr: NonNull<T>, len: usize, new_len: usize, pattern: F, ) -> Result<NonNull<T>, AllocError>
Reallocates a slice to a new length given the pointer to its first element, current length,
and requested length, filling any newly allocated bytes by calling pattern(i)
for each new
byte index i
.
On grow, preserves all existing elements and truncates to new_len
elements on shrink.
§Errors
AllocError::AllocFailed
if allocation fails.AllocError::InvalidLayout
if the computed slice would be zero-sized.AllocError::ZeroSizedLayout
if the computed slice would be zero-sized.
§Safety
ptr
must point to a slice allocated using this allocator.len
must describe exactly the number of elements in that slice.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.