Skip to main content

Writer

Struct Writer 

Source
pub struct Writer { /* private fields */ }
Expand description

小端序写入缓冲区。

Implementations§

Source§

impl Writer

Source

pub const fn new() -> Self

新建。

Source

pub fn with_capacity(n: usize) -> Self

预分配容量。

Source

pub fn len(&self) -> usize

当前长度。

Source

pub fn is_empty(&self) -> bool

是否为空。

Source

pub fn bytes(&mut self, b: &[u8]) -> &mut Self

追加原始字节。

Source

pub fn u8(&mut self, v: u8) -> &mut Self

追加 u8。

Source

pub fn u16le(&mut self, v: u16) -> &mut Self

追加小端序 u16。

Source

pub fn u32le(&mut self, v: u32) -> &mut Self

追加小端序 u32。

Source

pub fn u64le(&mut self, v: u64) -> &mut Self

追加小端序 u64。

Source

pub fn zeros(&mut self, n: usize) -> &mut Self

追加 n 个零字节。

Source

pub fn random(&mut self, n: usize) -> &mut Self

追加 n 个随机字节。

用于填充未使用的 key slot 与文件名 padding —— 必须是随机而非零, 否则「哪些 slot 在用」和「文件名多长」会直接暴露。

Source

pub fn pad_to(&mut self, total: usize) -> Result<&mut Self>

零填充到指定总长度。

§Errors

当前长度已超过目标时返回 Error::MalformedHeader。

Source

pub fn into_vec(self) -> Vec<u8> ⓘ

取出内部缓冲区。

Source

pub fn as_slice(&self) -> &[u8] ⓘ

借出内部缓冲区。

Trait Implementations§

Source§

impl Debug for Writer

Source§

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

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

impl Default for Writer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

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

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.