Skip to content

Struct std::io::BorrowedBuf

rust
pub struct BorrowedBuf<'data> { /* private fields */ }

增量填充和初始化的借用字节缓冲区。

这种类型是一种 “double cursor”。 它跟踪缓冲区中的三个区域:缓冲区开头的区域已被逻辑填充数据,已在某个时刻初始化但尚未逻辑填充的区域,以及完全未初始化的末尾区域。

填充区域保证是初始化区域的子集。

总之,缓冲区的内容可以可视化为:

rust
[             capacity              ]
[ filled |         unfilled         ]
[    initialized    | uninitialized ]

BorrowedBuf 是通过一个独特的引用 (&mut) 围绕一些现有数据 (或数据容量) 创建的。BorrowedBuf 可以配置 (例如,使用 clearset_init),但不能直接写入。 要写入缓冲区,请使用 unfilled 创建一个 BorrowedCursor。 游标对缓冲区的未填充部分具有只写访问权限 (您可以将其视为只写迭代器)。

生命周期 'data 是,底层,数据的生命周期的界限。

Implementations

impl<'data> BorrowedBuf<'data>

capacity

返回缓冲区的总容量。

rust
pub fn capacity(&self) -> usize

len

返回缓冲区填充部分的长度。

rust
pub fn len(&self) -> usize

init_len

返回缓冲区初始化部分的长度。

rust
pub fn init_len(&self) -> usize

filled

返回对缓冲区填充部分的共享引用。

rust
pub fn filled(&self) -> &[u8]

unfilled

返回缓冲区未填充部分上的游标。

rust
pub fn unfilled<'this>(&'this mut self) -> BorrowedCursor<'this>

clear

清除缓冲区,将填充区域重置为空。初始化的字节数不变,缓冲区的内容也不变。

rust
pub fn clear(&mut self) -> &mut Self

set_init

断言缓冲区的前 n 个字节已初始化。

rust
pub unsafe fn set_init(&mut self, n: usize) -> &mut Self

BorrowedBuf 假定字节永远不会被取消初始化,因此当调用该方法时使用的字节数少于已知要初始化的字节数时,该方法什么也不做。

Safety

调用者必须确保缓冲区的前 n 个未填充字节已经初始化。

Trait Implementations

impl Debug for BorrowedBuf<'_>

fmt

使用给定的格式化程序格式化该值。

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

impl<'data> From<&'data mut [MaybeUninit<u8>]> for BorrowedBuf<'data>

从未初始化的缓冲区创建一个新的 BorrowedBuf。

如果已知缓冲区的一部分已经初始化,则使用 set_init。

from

从输入类型转换为此类型。

rust
fn from(buf: &'data mut [MaybeUninit<u8>]) -> BorrowedBuf<'data>

impl<'data> From<&'data mut [u8]> for BorrowedBuf<'data>

从完全初始化的切片创建一个新的 BorrowedBuf。

from

从输入类型转换为此类型。

rust
fn from(slice: &'data mut [u8]) -> BorrowedBuf<'data>

Auto Trait Implementations

impl<'data> RefUnwindSafe for BorrowedBuf<'data>

impl<'data> Send for BorrowedBuf<'data>

impl<'data> Sync for BorrowedBuf<'data>

impl<'data> Unpin for BorrowedBuf<'data>

impl<'data> !UnwindSafe for BorrowedBuf<'data>

Blanket Implementations

impl<T> Any for T

rust
impl<T> Any for T
where
  T: 'static + ?Sized,

impl<T> Borrow<T> for T

rust
impl<T> Borrow<T> for T
where
  T: ?Sized,

impl<T> BorrowMut<T> for T

rust
impl<T> BorrowMut<T> for T
where
  T: ?Sized,

impl<T> From<T> for T

impl<T, U> Into<U> for T

rust
impl<T, U> Into<U> for T
where
  U: From<T>,

impl<T, U> TryFrom<U> for T

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

impl<T, U> TryInto<U> for T

rust
impl<T, U> TryInto<U> for T
where
  U: TryFrom<T>,

MIT Licensed