跳到主要内容

Split

搜索

结构体 Split 

Source
pub struct Split<R> { /* private fields */ }
展开描述

split 方法使用的分割器。

Split 可以通过 SplitStream 转换为 Stream

实现§

Source§

impl<R> Split<R>
where R: AsyncBufRead + Unpin,

Source

pub async fn next_segment(&mut self) -> Result<Option<Vec<u8>>>

返回流中的下一段。

§示例
use tokio::io::AsyncBufReadExt;

let mut segments = my_buf_read.split(b'f');

while let Some(segment) = segments.next_segment().await? {
    println!("length = {}", segment.len())
}
Source§

impl<R> Split<R>
where R: AsyncBufRead,

Source

pub fn poll_next_segment( self: Pin<&mut Self>, cx: &mut Context<'_>, ) -> Poll<Result<Option<Vec<u8>>>>

轮询流中的下一段。

此方法返回:

  • Poll::Pending if the next segment is not yet available.
  • Poll::Ready(Ok(Some(segment))) if the next segment is available.
  • Poll::Ready(Ok(None)) if there are no more segments in this stream.
  • Poll::Ready(Err(err)) if an IO error occurred while reading the next segment.

当方法返回 Poll::Pending 时,传入的 Context 中的 Waker 会被调度, 以便在底层 I/O 资源上有更多字节可用时收到唤醒通知。

请注意,对 poll_next_segment 的多次调用中, 只有最近一次调用传入的 Context 中的 Waker 会被调度接收唤醒。

Trait 实现§

Source§

impl<R: Debug> Debug for Split<R>

Source§

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

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

impl<'__pin, R> Unpin for Split<R>
where PinnedFieldsOf<__Origin<'__pin, R>>: Unpin,

自动 Trait 实现§

§

impl<R> Freeze for Split<R>
where R: Freeze,

§

impl<R> RefUnwindSafe for Split<R>
where R: RefUnwindSafe,

§

impl<R> Send for Split<R>
where R: Send,

§

impl<R> Sync for Split<R>
where R: Sync,

§

impl<R> UnsafeUnpin for Split<R>
where R: UnsafeUnpin,

§

impl<R> UnwindSafe for Split<R>
where R: 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)

也就是说,此转换的具体行为取决于 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>

执行转换。