BufferExt

Trait BufferExt 

Source
pub trait BufferExt {
    // Required methods
    fn read_all(&self) -> Vec<u8> ;
    fn read_to_string(&self) -> VtxResult<String>;
    fn read_json<T: DeserializeOwned>(&self) -> VtxResult<T>;
    fn write_all(&self, data: impl AsRef<[u8]>) -> u64;
}
Expand description

Buffer 资源的便捷扩展方法。

Required Methods§

Source

fn read_all(&self) -> Vec<u8>

读取整个 Buffer。

  • 对于 file/memory:使用 size() 做分块读取。
  • 对于 pipe:会持续读取直到 EOF(返回空数组)或到达 max_total_bytes
Source

fn read_to_string(&self) -> VtxResult<String>

按 UTF-8 读取整个 Buffer。

Source

fn read_json<T: DeserializeOwned>(&self) -> VtxResult<T>

将 Buffer 中的 JSON 反序列化为目标类型。

Source

fn write_all(&self, data: impl AsRef<[u8]>) -> u64

向 Buffer 追加写入(对文件:append;对 pipe:写入 stdin;对 memory:append)。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§