DivBufShared

Struct DivBufShared 

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

Source§

impl DivBufShared

Source

pub fn capacity(&self) -> usize

Returns the number of bytes the buffer can hold without reallocating.

Source

pub fn is_empty(&self) -> bool

Returns true if the DivBufShared has length 0

Source

pub fn len(&self) -> usize

Returns the number of bytes contained in this buffer.

Source

pub fn try_const(&self) -> Result<DivBuf, Error>

Try to create a read-only DivBuf that refers to the entirety of this buffer. Will fail if there are any DivBufMut objects referring to this buffer.

§Examples
let dbs = DivBufShared::with_capacity(4096);
let db = dbs.try_const().unwrap();
Source

pub fn try_mut(&self) -> Result<DivBufMut, Error>

Try to create a mutable DivBufMut that refers to the entirety of this buffer. Will fail if there are any DivBufMut or DivBuf objects referring to this buffer.

§Examples
let dbs = DivBufShared::with_capacity(4096);
let dbm = dbs.try_mut().unwrap();
Source

pub fn uninitialized(capacity: usize) -> Self

Available on crate feature 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.

https://github.com/rust-lang/rust/issues/78485

Source

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§

impl Debug for DivBufShared

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Drop for DivBufShared

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a> From<&'a [u8]> for DivBufShared

Source§

fn from(src: &'a [u8]) -> DivBufShared

Converts to this type from the input type.
Source§

impl From<Vec<u8>> for DivBufShared

Source§

fn from(src: Vec<u8>) -> DivBufShared

Converts to this type from the input type.
Source§

impl TryFrom<DivBufShared> for Vec<u8>

Source§

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]);
Source§

type Error = DivBufShared

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

impl Send for DivBufShared

Source§

impl Sync for DivBufShared

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.