Struct Split

struct Split<R> { ... }

Splitter for the split method.

A Split can be turned into a Stream with SplitStream.

Implementations

impl<R> Split<R>

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

Returns the next segment in the stream.

Examples

# use tokio::io::AsyncBufRead;
use tokio::io::AsyncBufReadExt;

# async fn dox(my_buf_read: impl AsyncBufRead + Unpin) -> std::io::Result<()> {
let mut segments = my_buf_read.split(b'f');

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

impl<R> Split<R>

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

Polls for the next segment in the stream.

This method returns:

  • 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.

When the method returns Poll::Pending, the Waker in the provided Context is scheduled to receive a wakeup when more bytes become available on the underlying IO resource.

Note that on multiple calls to poll_next_segment, only the Waker from the Context passed to the most recent call is scheduled to receive a wakeup.

impl<'__pin, R> Unpin for Split<R>

impl<R> Freeze for Split<R>

impl<R> RefUnwindSafe for Split<R>

impl<R> Send for Split<R>

impl<R> Sync for Split<R>

impl<R> UnsafeUnpin for Split<R>

impl<R> UnwindSafe for Split<R>

impl<R: $crate::fmt::Debug> Debug for Split<R>

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

impl<T> Any for Split<R>

fn type_id(self: &Self) -> TypeId

impl<T> Borrow for Split<R>

fn borrow(self: &Self) -> &T

impl<T> BorrowMut for Split<R>

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

impl<T> From for Split<R>

fn from(t: T) -> T

Returns the argument unchanged.

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

fn into(self: Self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

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

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

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

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