[−][src]Type Definition swim_mem::lease::RawBuf
type RawBuf<'a, T, M = ()> = Raw<'a, Buf<T, M>>;
Exclusive reference to a resizeable array of values stored in a
Hold
-allocated memory block, with buffer length and capacity metadata
stored alongside the pointer.
Storing buffer metadata in the pointer structure keeps the allocated memory block exactly the size of the buffer capacity.
Examples
Create an empty RawBuf
that will allocate space in the global hold:
let buf = RawBuf::<u8>::empty();
Clone a slice into a newly allocated RawBuf
:
let buf = RawBuf::<u8>::from_clone(&[2, 3]);
Push values onto the end of a RawBuf
, growing its capacity as needed:
let mut buf = RawBuf::<u8>::from_clone(&[1, 2]); buf.push(3);
Pop values off of the end of a RawBuf
:
let mut buf = RawBuf::<u8>::from_clone(&[1, 2]); let two = buf.pop();
Access elements by index:
let mut buf = RawBuf::<u8>::from_clone(&[1, 2, 3]); let three = buf[2]; buf[1] *= 2;