pub struct DivBufShared { /* private fields */ }Expand description
The “entry point” to the divbuf crate.
A DivBufShared owns storage, but cannot directly access it. An
application will typically create an instance of this class for every
independent buffer it wants to manage, and then create child DivBufs or
DivBufMuts to access the storage.
Implementations§
Sourcepub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of bytes the buffer can hold without reallocating.
Sourcepub fn uninitialized(capacity: usize) -> Self
Available on crate feature experimental only.
pub fn uninitialized(capacity: usize) -> Self
experimental only.Create a new DivBufShared with an uninitialized buffer of specified length.
§Safety
This method technically causes undefined behavior, but it works with current compilers. A good replacement is not possible until the read-buf feature stabilizes.
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Creates a new, empty, DivBufShared with a specified capacity.
After constructing a DivBufShared this way, it can only be populated
via a child DivBufMut.
Trait Implementations§
Source§fn from(src: &'a [u8]) -> DivBufShared
fn from(src: &'a [u8]) -> DivBufShared
Source§fn try_from(buf: DivBufShared) -> Result<Self, Self::Error>
fn try_from(buf: DivBufShared) -> Result<Self, Self::Error>
Attempt to extract the owned storage from a DivBufShared.
This will fail if there are any other living references to this same
DivBufShared (DivBufs, DivBufMuts, etc), in which case the
DivBufShared will be returned unmodified.
§Examples
use std::convert::TryInto;
let dbs = DivBufShared::from(vec![1, 2, 3, 4, 5, 6]);
let vec: Vec<u8> = dbs.try_into().unwrap();
assert_eq!(vec, vec![1, 2, 3, 4, 5, 6]);