Spec-Zone.ru › Tokio

Function simplex

pub fn simplex(
    max_buf_size: usize,
) -> (ReadHalf<SimplexStream>, WriteHalf<SimplexStream>)
Available on crate feature io-util only.

Creates unidirectional buffer that acts like in memory pipe.

The max_buf_size argument is the maximum amount of bytes that can be written to a buffer before it returns Poll::Pending.

Unify reader and writer

The reader and writer half can be unified into a single structure of SimplexStream that supports both reading and writing or the SimplexStream can be already created as unified structure using SimplexStream::new_unsplit().

let (reader, writer) = tokio::io::simplex(64);
let mut simplex_stream = reader.unsplit(writer);
simplex_stream.write_all(b"hello").await?;

let mut buf = [0u8; 5];
simplex_stream.read_exact(&mut buf).await?;
assert_eq!(&buf, b"hello");

MIT License
Copyright © Tokio Contributors
https://docs.rs/tokio/1.53.1/tokio/io/fn.simplex.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API