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>
impl<R: AsyncRead + Unpin> AsciiStreamReaderAsync<R>
Sourcepub fn new(inner: R) -> Self
pub fn new(inner: R) -> Self
Creates a new AsciiStreamReaderAsync with a default buffer capacity.
Sourcepub fn with_capacity(capacity: usize, inner: R) -> Self
pub fn with_capacity(capacity: usize, inner: R) -> Self
Creates a new AsciiStreamReaderAsync with the specified buffer capacity.
Sourcepub async fn read_line(&mut self, buf: &mut AsciiString) -> ReadLineResult
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.
Sourcepub async fn read_until(
&mut self,
byte: u8,
buf: &mut AsciiString,
) -> Result<usize>
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.
Sourcepub async fn read_to_end(&mut self, buf: &mut AsciiString) -> Result<usize>
pub async fn read_to_end(&mut self, buf: &mut AsciiString) -> Result<usize>
Reads all data from the stream until EOF is encountered.
Sourcepub async fn read_bytes(
&mut self,
buf: &mut AsciiString,
len: usize,
) -> Result<usize>
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§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more