AsciiStreamReaderAsync

Struct AsciiStreamReaderAsync 

Source
pub struct AsciiStreamReaderAsync<R> { /* private fields */ }
Expand description

An asynchronous buffered reader which reads data as ascii characters.

§Examples

async fn read_example() {
    use futures::io::Cursor;
    use cj_ascii::ascii_stream_async::AsciiStreamReaderAsync;
    use cj_ascii::ascii_string::AsciiString;

    let mut stream = AsciiStreamReaderAsync::new(Cursor::new(b"abc\r\ndef\r\nghi"));
    let mut buf = AsciiString::new();
    while stream.read_line(&mut buf).await.is_success() {
        println!("{}", buf);
    }
}

tokio example

async fn read_example_tokio() {
    use cj_ascii::ascii_stream_async::AsciiStreamReaderAsync;
    use cj_ascii::ascii_string::AsciiString;
    use tokio_util::compat::*;

    let file_name = "C:/Temp/EnglishWords/words_ansi.txt";
    let file = tokio::fs::File::open(file_name).await.unwrap();
    let mut stream = AsciiStreamReaderAsync::new(file.compat());

    let mut line = AsciiString::new();
    while stream.read_line(&mut line).await.is_success() {
        println!("{}", line);
    }
}

Implementations§

Source§

impl<R: AsyncRead + Unpin> AsciiStreamReaderAsync<R>

Source

pub fn new(inner: R) -> Self

Creates a new AsciiStreamReaderAsync with a default buffer capacity.

Source

pub fn with_capacity(capacity: usize, inner: R) -> Self

Creates a new AsciiStreamReaderAsync with the specified buffer capacity.

Source

pub async fn read_line(&mut self, buf: &mut AsciiString) -> ReadLineResult

Reads a line from the stream into the specified buffer, removing the line ending.

Source

pub async fn read_until( &mut self, byte: u8, buf: &mut AsciiString, ) -> Result<usize>

Reads data from the stream until the specified byte is encountered.

  • The specified byte is included in the returned data.
Source

pub async fn read_to_end(&mut self, buf: &mut AsciiString) -> Result<usize>

Reads all data from the stream until EOF is encountered.

Source

pub async fn read_bytes( &mut self, buf: &mut AsciiString, len: usize, ) -> Result<usize>

Reads the specified number of bytes from the stream.

Trait Implementations§

Source§

impl<R: Debug> Debug for AsciiStreamReaderAsync<R>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

impl<R> Unpin for AsciiStreamReaderAsync<R>
where R: Unpin,

§

impl<R> UnwindSafe for AsciiStreamReaderAsync<R>
where R: 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<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.

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.