Struct smol::io::AssertAsync

source ·
pub struct AssertAsync<T>(/* private fields */);
Expand description

Asserts that a type implementing std::io traits can be used as an async type.

The underlying I/O handle should never block nor return the ErrorKind::WouldBlock error. This is usually the case for in-memory buffered I/O.

Examples

use futures_lite::io::{AssertAsync, AsyncReadExt};

let reader: &[u8] = b"hello";

let mut async_reader = AssertAsync::new(reader);
let mut contents = String::new();

// This line works in async manner - note that there is await:
async_reader.read_to_string(&mut contents).await?;

Implementations§

source§

impl<T> AssertAsync<T>

source

pub fn new(io: T) -> AssertAsync<T>

Wraps an I/O handle implementing std::io traits.

Examples
use futures_lite::io::AssertAsync;

let reader: &[u8] = b"hello";

let async_reader = AssertAsync::new(reader);
source

pub fn get_ref(&self) -> &T

Gets a reference to the inner I/O handle.

Examples
use futures_lite::io::AssertAsync;

let reader: &[u8] = b"hello";

let async_reader = AssertAsync::new(reader);
let r = async_reader.get_ref();
source

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

Gets a mutable reference to the inner I/O handle.

Examples
use futures_lite::io::AssertAsync;

let reader: &[u8] = b"hello";

let mut async_reader = AssertAsync::new(reader);
let r = async_reader.get_mut();
source

pub fn into_inner(self) -> T

Extracts the inner I/O handle.

Examples
use futures_lite::io::AssertAsync;

let reader: &[u8] = b"hello";

let async_reader = AssertAsync::new(reader);
let inner = async_reader.into_inner();

Trait Implementations§

source§

impl<T> AsyncRead for AssertAsync<T>
where T: Read,

source§

fn poll_read( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, buf: &mut [u8] ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into buf. Read more
source§

fn poll_read_vectored( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>] ) -> Poll<Result<usize, Error>>

Attempt to read from the AsyncRead into bufs using vectored IO operations. Read more
source§

impl<T> AsyncSeek for AssertAsync<T>
where T: Seek,

source§

fn poll_seek( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, pos: SeekFrom ) -> Poll<Result<u64, Error>>

Attempt to seek to an offset, in bytes, in a stream. Read more
source§

impl<T> AsyncWrite for AssertAsync<T>
where T: Write,

source§

fn poll_write( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, buf: &[u8] ) -> Poll<Result<usize, Error>>

Attempt to write bytes from buf into the object. Read more
source§

fn poll_write_vectored( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_>, bufs: &[IoSlice<'_>] ) -> Poll<Result<usize, Error>>

Attempt to write bytes from bufs into the object using vectored IO operations. Read more
source§

fn poll_flush( self: Pin<&mut AssertAsync<T>>, _: &mut Context<'_> ) -> Poll<Result<(), Error>>

Attempt to flush the object, ensuring that any buffered data reach their destination. Read more
source§

fn poll_close( self: Pin<&mut AssertAsync<T>>, cx: &mut Context<'_> ) -> Poll<Result<(), Error>>

Attempt to close the object. Read more
source§

impl<T> Clone for AssertAsync<T>
where T: Clone,

source§

fn clone(&self) -> AssertAsync<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for AssertAsync<T>
where T: Debug,

source§

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

Formats the value using the given formatter. Read more
source§

impl<T> Hash for AssertAsync<T>
where T: Hash,

source§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl<T> Ord for AssertAsync<T>
where T: Ord,

source§

fn cmp(&self, other: &AssertAsync<T>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl<T> PartialEq for AssertAsync<T>
where T: PartialEq,

source§

fn eq(&self, other: &AssertAsync<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T> PartialOrd for AssertAsync<T>
where T: PartialOrd,

source§

fn partial_cmp(&self, other: &AssertAsync<T>) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<T> Copy for AssertAsync<T>
where T: Copy,

source§

impl<T> Eq for AssertAsync<T>
where T: Eq,

source§

impl<T> StructuralEq for AssertAsync<T>

source§

impl<T> StructuralPartialEq for AssertAsync<T>

source§

impl<T> Unpin for AssertAsync<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for AssertAsync<T>
where T: RefUnwindSafe,

§

impl<T> Send for AssertAsync<T>
where T: Send,

§

impl<T> Sync for AssertAsync<T>
where T: Sync,

§

impl<T> UnwindSafe for AssertAsync<T>
where T: UnwindSafe,

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<R> AsyncReadExt for R
where R: AsyncRead + ?Sized,

source§

fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>
where Self: Unpin,

Reads some bytes from the byte stream. Read more
source§

fn read_vectored<'a>( &'a mut self, bufs: &'a mut [IoSliceMut<'a>] ) -> ReadVectoredFuture<'a, Self>
where Self: Unpin,

Like read(), except it reads into a slice of buffers. Read more
source§

fn read_to_end<'a>( &'a mut self, buf: &'a mut Vec<u8> ) -> ReadToEndFuture<'a, Self>
where Self: Unpin,

Reads the entire contents and appends them to a Vec. Read more
source§

fn read_to_string<'a>( &'a mut self, buf: &'a mut String ) -> ReadToStringFuture<'a, Self>
where Self: Unpin,

Reads the entire contents and appends them to a String. Read more
source§

fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>
where Self: Unpin,

Reads the exact number of bytes required to fill buf. Read more
source§

fn take(self, limit: u64) -> Take<Self>
where Self: Sized,

Creates an adapter which will read at most limit bytes from it. Read more
source§

fn bytes(self) -> Bytes<Self>
where Self: Sized,

Converts this AsyncRead into a Stream of bytes. Read more
source§

fn chain<R>(self, next: R) -> Chain<Self, R>
where R: AsyncRead, Self: Sized,

Creates an adapter which will chain this stream with another. Read more
source§

fn boxed_reader<'a>(self) -> Pin<Box<dyn AsyncRead + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
source§

impl<S> AsyncSeekExt for S
where S: AsyncSeek + ?Sized,

source§

fn seek(&mut self, pos: SeekFrom) -> SeekFuture<'_, Self>
where Self: Unpin,

Seeks to a new position in a byte stream. Read more
source§

impl<W> AsyncWriteExt for W
where W: AsyncWrite + ?Sized,

source§

fn write<'a>(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>
where Self: Unpin,

Writes some bytes into the byte stream. Read more
source§

fn write_vectored<'a>( &'a mut self, bufs: &'a [IoSlice<'a>] ) -> WriteVectoredFuture<'a, Self>
where Self: Unpin,

Like write(), except that it writes a slice of buffers. Read more
source§

fn write_all<'a>(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>
where Self: Unpin,

Writes an entire buffer into the byte stream. Read more
source§

fn flush(&mut self) -> FlushFuture<'_, Self>
where Self: Unpin,

Flushes the stream to ensure that all buffered contents reach their destination. Read more
source§

fn close(&mut self) -> CloseFuture<'_, Self>
where Self: Unpin,

Closes the writer. Read more
source§

fn boxed_writer<'a>(self) -> Pin<Box<dyn AsyncWrite + Send + 'a>>
where Self: Sized + Send + 'a,

Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

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

source§

fn into(self) -> U

Calls U::from(self).

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

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
source§

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

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more