pub struct BufMut<T: PackedElement, const DIM: usize>(/* private fields */);Expand description
A buffer of packed values that is statically the only reference to its storage, like a
Vec: it is written without ever checking whether its storage is shared, it grows
along one dimension, and it turns into a Buf to be shared, see Self::freeze. A Buf turns
into one with copy-on-write, see Buf::make_mut and Buf::into_mut.
It cannot be sliced, which would share its storage, and cloning it copies its values
into a storage of their own, like a Vec. An empty one may have no storage of its own,
see Self::new, until it first grows.
Implementations§
Source§impl<T: PackedElement, const DIM: usize> BufMut<T, DIM>
impl<T: PackedElement, const DIM: usize> BufMut<T, DIM>
Sourcepub fn zeroed(dim: [usize; DIM]) -> Self
pub fn zeroed(dim: [usize; DIM]) -> Self
A buffer of zeroes with those dimensions, held in place for a scalar.
§Panics
If the dimensions are too large for a storage.
Sourcepub fn from_slice(values: &[T], dim: [usize; DIM]) -> Option<Self>
pub fn from_slice(values: &[T], dim: [usize; DIM]) -> Option<Self>
A buffer of these values, see Buf::from_slice.
pub fn is_empty(&self) -> bool
pub fn as_slice(&self) -> &[T]
pub fn as_mut_slice(&mut self) -> &mut [T]
pub fn as_bytes(&self) -> &[u8] ⓘ
Sourcepub fn freeze(self) -> Buf<T, DIM>
pub fn freeze(self) -> Buf<T, DIM>
Share this buffer, which cannot be written anymore unless it is the only reference
to its storage again, see Buf::try_into_mut.
Source§impl<T: PackedElement> BufMut<T, 1>
impl<T: PackedElement> BufMut<T, 1>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
An empty buffer, which allocates nothing until it grows, see Buf::new.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
An empty buffer that can grow to at least that many values without reallocating.
Sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Make room for at least that many more values, growing the storage if it lacks room.
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), Error>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), Error>
Self::reserve, failing rather than aborting when the allocation does, which
leaves the buffer as it was: for a length that comes off the wire.
Sourcepub fn extend_from_slice(&mut self, values: &[T])
pub fn extend_from_slice(&mut self, values: &[T])
Append these values.
Source§impl BufMut<u8, 1>
impl BufMut<u8, 1>
Sourcepub fn set_len(&mut self, len: usize)
pub fn set_len(&mut self, len: usize)
Grow or shrink to that many octets, the added ones being left as they are, which saves zeroing octets that are about to be written: they are zeroes, unless this buffer held something there before it was shrunk or cleared.
This is only for octets, every one of which is valid, unlike what was left there for other types.