[−][src]Type Definition swim_mem::lease::PtrBuf
type PtrBuf<'a, T, M = ()> = Ptr<'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 inside the allocation.
Storing buffer metadata in the memory block keeps the pointer structure exactly the size of an element pointer.
Examples
Create an empty PtrBuf
that will allocate space in the global hold:
let buf = PtrBuf::<u8>::empty();
Clone a slice into a newly allocated PtrBuf
:
let buf = PtrBuf::<u8>::from_clone(&[2, 3]);
Push values onto the end of a PtrBuf
, growing its capacity as needed:
let mut buf = PtrBuf::<u8>::from_clone(&[1, 2]); buf.push(3);
Pop values off of the end of a PtrBuf
:
let mut buf = PtrBuf::<u8>::from_clone(&[1, 2]); let two = buf.pop();
Access elements by index:
let mut buf = PtrBuf::<u8>::from_clone(&[1, 2, 3]); let three = buf[2]; buf[1] *= 2;