跳到主要内容

Writer

搜索

结构体 Writer 

Source
pub struct Writer<B> { /* private fields */ }
展开描述

一个为内部值实现 io::WriteBufMut 适配器。

此结构体通常通过对 BufMut 调用 writer() 创建。详情请参阅 writer() 的文档。

实现§

Source§

impl<B: BufMut> Writer<B>

Source

pub fn get_ref(&self) -> &B

获取对底层 BufMut 的引用。

不建议直接写入底层 BufMut

§示例
use bytes::BufMut;

let buf = Vec::with_capacity(1024).writer();

assert_eq!(1024, buf.get_ref().capacity());
Source

pub fn get_mut(&mut self) -> &mut B

获取对底层 BufMut 的可变引用。

不建议直接写入底层 BufMut

§示例
use bytes::BufMut;

let mut buf = vec![].writer();

buf.get_mut().reserve(1024);

assert_eq!(1024, buf.get_ref().capacity());
Source

pub fn into_inner(self) -> B

消耗此 Writer,返回底层的值。

§示例
use bytes::BufMut;
use std::io;

let mut buf = vec![].writer();
let mut src = &b"hello world"[..];

io::copy(&mut src, &mut buf).unwrap();

let buf = buf.into_inner();
assert_eq!(*buf, b"hello world"[..]);

Trait 实现§

Source§

impl<B: Debug> Debug for Writer<B>

Source§

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

使用给定的格式化器格式化此值。 更多信息
Source§

impl<B: BufMut + Sized> Write for Writer<B>

Source§

fn write(&mut self, src: &[u8]) -> Result<usize>

Writes a buffer into this writer, returning how many bytes were written. 更多信息
Source§

fn flush(&mut self) -> Result<()>

Flushes this output stream, ensuring that all intermediately buffered contents reach their destination. 更多信息
1.36.0 · Source§

fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>

Like write, except that it writes from a slice of buffers. 更多信息
Source§

fn is_write_vectored(&self) -> bool

🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. 更多信息
1.0.0 · Source§

fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>

Attempts to write an entire buffer into this writer. 更多信息
Source§

fn write_all_vectored(&mut self, bufs: &mut [IoSlice<'_>]) -> Result<(), Error>

🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. 更多信息
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Writes a formatted string into this writer, returning any error encountered. 更多信息
1.0.0 · Source§

fn by_ref(&mut self) -> &mut Self
where Self: Sized,

Creates a “by reference” adapter for this instance of Write. 更多信息

自动 Trait 实现§

§

impl<B> Freeze for Writer<B>
where B: Freeze,

§

impl<B> RefUnwindSafe for Writer<B>
where B: RefUnwindSafe,

§

impl<B> Send for Writer<B>
where B: Send,

§

impl<B> Sync for Writer<B>
where B: Sync,

§

impl<B> Unpin for Writer<B>
where B: Unpin,

§

impl<B> UnsafeUnpin for Writer<B>
where B: UnsafeUnpin,

§

impl<B> UnwindSafe for Writer<B>
where B: UnwindSafe,

Blanket 实现§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. 更多信息
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. 更多信息
Source§

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

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. 更多信息
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

原样返回传入的参数。

Source§

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

Source§

fn into(self) -> U

调用 U::from(self)

That is, this conversion is whatever the implementation of From<T> for U 的实现方式。

Source§

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

Source§

type Error = Infallible

转换出错时返回的类型。
Source§

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

执行转换。
Source§

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

Source§

type Error = <U as TryFrom<T>>::Error

转换出错时返回的类型。
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

执行转换。