Skip to main content

BufMut

Struct BufMut 

Source
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>

Source

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.

Source

pub fn from_slice(values: &[T], dim: [usize; DIM]) -> Option<Self>

A buffer of these values, see Buf::from_slice.

Source

pub fn dim(&self) -> [usize; DIM]

The dimensions of this buffer, see Buf::dim.

Source

pub fn len(&self) -> usize

The number of values of this buffer, 1 for a scalar.

Source

pub fn is_empty(&self) -> bool

Source

pub fn as_ptr(&self) -> *const T

Where the values of this buffer start.

Source

pub fn as_slice(&self) -> &[T]

Source

pub fn as_mut_slice(&mut self) -> &mut [T]

Source

pub fn as_bytes(&self) -> &[u8] ⓘ

Source

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>

Source

pub const fn new() -> Self

An empty buffer, which allocates nothing until it grows, see Buf::new.

Source

pub fn with_capacity(capacity: usize) -> Self

An empty buffer that can grow to at least that many values without reallocating.

Source

pub fn capacity(&self) -> usize

How many values this buffer can hold without reallocating.

Source

pub fn reserve(&mut self, additional: usize)

Make room for at least that many more values, growing the storage if it lacks room.

Source

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.

Source

pub fn push(&mut self, value: T)

Append that value.

Source

pub fn extend_from_slice(&mut self, values: &[T])

Append these values.

Source

pub fn resize(&mut self, len: usize, value: T)

Grow or shrink to that many values, the added ones being that value.

Zeroes are only written up to the capacity this buffer had before growing: what a storage grows by is already zeroed.

Source

pub fn truncate(&mut self, len: usize)

Keep only the first values, no more than that many.

Source

pub fn clear(&mut self)

Empty this buffer, keeping its storage, and so its capacity, and freeing what the buffers cast from it had attached to it.

Source§

impl BufMut<u8, 1>

Source

pub fn from_hex(s: &str) -> Option<Self>

Parse plain hexadecimal octets, in either case, which is what UpperHex and LowerHex give, absent if they are not.

Source

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.

Trait Implementations§

Source§

impl<T: PackedElement, const DIM: usize> Clone for BufMut<T, DIM>

Source§

fn clone(&self) -> Self

A copy of the values of this buffer, in a storage of their own, the capacity past them not being kept.

1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: PackedElement, const DIM: usize> Debug for BufMut<T, DIM>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Its dimensions and values, row by row, see Element::fmt_row.

Source§

impl<T: PackedElement> Default for BufMut<T, 1>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<T: PackedElement + Eq, const DIM: usize> Eq for BufMut<T, DIM>

Source§

impl<T: PackedElement> From<&[T]> for BufMut<T, 1>

Source§

fn from(values: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<T: PackedElement, const DIM: usize> From<BufMut<T, DIM>> for Buf<T, DIM>

Source§

fn from(buf: BufMut<T, DIM>) -> Self

Converts to this type from the input type.
Source§

impl<T: PackedElement> From<Vec<T>> for BufMut<T, 1>

Source§

fn from(values: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T: PackedElement> LowerHex for BufMut<T, 1>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The octets of the values as hexadecimal, in the order they are stored, each value’s grouped and separated by a space, octets being a single run that BufMut::from_hex parses back.

Source§

impl<T: PackedElement + PartialEq, const DIM: usize> PartialEq for BufMut<T, DIM>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PackedElement> UpperHex for BufMut<T, 1>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

The octets of the values as hexadecimal, in the order they are stored, each value’s grouped and separated by a space, octets being a single run that BufMut::from_hex parses back.

Auto Trait Implementations§

§

impl<T, const DIM: usize> Freeze for BufMut<T, DIM>
where Buf<T, DIM>: Freeze,

§

impl<T, const DIM: usize> RefUnwindSafe for BufMut<T, DIM>
where Buf<T, DIM>: RefUnwindSafe,

§

impl<T, const DIM: usize> Send for BufMut<T, DIM>
where Buf<T, DIM>: Send,

§

impl<T, const DIM: usize> Sync for BufMut<T, DIM>
where Buf<T, DIM>: Sync,

§

impl<T, const DIM: usize> Unpin for BufMut<T, DIM>
where Buf<T, DIM>: Unpin,

§

impl<T, const DIM: usize> UnsafeUnpin for BufMut<T, DIM>
where Buf<T, DIM>: UnsafeUnpin,

§

impl<T, const DIM: usize> UnwindSafe for BufMut<T, DIM>
where Buf<T, DIM>: UnwindSafe,

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Model for T
where T: Send + Sync + 'static,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more