Struct grafix_toolbox::uses::Async::io::Cursor [−]
pub struct Cursor<T> { /* fields omitted */ }Expand description
Gives an in-memory buffer a cursor for reading and writing.
Examples
use futures_lite::io::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt, Cursor, SeekFrom}; let mut bytes = b"hello".to_vec(); let mut cursor = Cursor::new(&mut bytes); // Overwrite 'h' with 'H'. cursor.write_all(b"H").await?; // Move the cursor one byte forward. cursor.seek(SeekFrom::Current(1)).await?; // Read a byte. let mut byte = [0]; cursor.read_exact(&mut byte).await?; assert_eq!(&byte, b"l"); // Check the final buffer. assert_eq!(bytes, b"Hello");
Implementations
impl<T> Cursor<T>
impl<T> Cursor<T>Creates a cursor for an in-memory buffer.
Cursor’s initial position is 0 even if the underlying buffer is not empty. Writing using
Cursor will overwrite the existing contents unless the cursor is moved to the end of
the buffer using set_position() or
[seek()][AsyncSeekExt::seek()].
Examples
use futures_lite::io::Cursor; let cursor = Cursor::new(Vec::<u8>::new());
Gets a reference to the underlying buffer.
Examples
use futures_lite::io::Cursor; let cursor = Cursor::new(Vec::<u8>::new()); let r = cursor.get_ref();
Gets a mutable reference to the underlying buffer.
Examples
use futures_lite::io::Cursor; let mut cursor = Cursor::new(Vec::<u8>::new()); let r = cursor.get_mut();
pub fn into_inner(self) -> T
pub fn into_inner(self) -> TUnwraps the cursor, returning the underlying buffer.
Examples
use futures_lite::io::Cursor; let cursor = Cursor::new(vec![1, 2, 3]); assert_eq!(cursor.into_inner(), [1, 2, 3]);
Returns the current position of this cursor.
Examples
use futures_lite::io::{AsyncSeekExt, Cursor, SeekFrom}; let mut cursor = Cursor::new(b"hello"); assert_eq!(cursor.position(), 0); cursor.seek(SeekFrom::Start(2)).await?; assert_eq!(cursor.position(), 2);
pub fn set_position(&mut self, pos: u64)
pub fn set_position(&mut self, pos: u64)Sets the position of this cursor.
Examples
use futures_lite::io::Cursor; let mut cursor = Cursor::new(b"hello"); assert_eq!(cursor.position(), 0); cursor.set_position(2); assert_eq!(cursor.position(), 2);
Trait Implementations
Attempt to return the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Attempt to read from the AsyncRead into buf. Read more
impl<'_> AsyncWrite for Cursor<&'_ mut [u8]>
impl<'_> AsyncWrite for Cursor<&'_ mut [u8]>impl AsyncWrite for Cursor<Vec<u8, Global>>
impl AsyncWrite for Cursor<Vec<u8, Global>>impl<'_> AsyncWrite for Cursor<&'_ mut Vec<u8, Global>>
impl<'_> AsyncWrite for Cursor<&'_ mut Vec<u8, Global>>Auto Trait Implementations
impl<T> RefUnwindSafe for Cursor<T> where
T: RefUnwindSafe, impl<T> UnwindSafe for Cursor<T> where
T: UnwindSafe, Blanket Implementations
impl<R> AsyncBufReadExt for R where
R: AsyncBufRead + ?Sized,
impl<R> AsyncBufReadExt for R where
R: AsyncBufRead + ?Sized, Returns the contents of the internal buffer, filling it with more data if empty. Read more
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntilFuture<'a, Self>ⓘNotable traits for ReadUntilFuture<'_, R>
impl<'_, R> Future for ReadUntilFuture<'_, R> where
R: AsyncBufRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntilFuture<'a, Self>ⓘNotable traits for ReadUntilFuture<'_, R>
impl<'_, R> Future for ReadUntilFuture<'_, R> where
R: AsyncBufRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, Reads all bytes and appends them into buf until the delimiter byte or EOF is found. Read more
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self>ⓘNotable traits for ReadLineFuture<'_, R>
impl<'_, R> Future for ReadLineFuture<'_, R> where
R: AsyncBufRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self>ⓘNotable traits for ReadLineFuture<'_, R>
impl<'_, R> Future for ReadLineFuture<'_, R> where
R: AsyncBufRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, Reads all bytes and appends them into buf until a newline (the 0xA byte) or EOF is found. Read more
Returns a stream over the lines of this byte stream. Read more
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized, Reads some bytes from the byte stream. Read more
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘNotable traits for ReadVectoredFuture<'_, R>
impl<'_, R> Future for ReadVectoredFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘNotable traits for ReadVectoredFuture<'_, R>
impl<'_, R> Future for ReadVectoredFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self>ⓘNotable traits for ReadToEndFuture<'_, R>
impl<'_, R> Future for ReadToEndFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn read_to_end(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEndFuture<'a, Self>ⓘNotable traits for ReadToEndFuture<'_, R>
impl<'_, R> Future for ReadToEndFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘNotable traits for ReadToStringFuture<'_, R>
impl<'_, R> Future for ReadToStringFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘNotable traits for ReadToStringFuture<'_, R>
impl<'_, R> Future for ReadToStringFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>ⓘNotable traits for ReadExactFuture<'_, R>
impl<'_, R> Future for ReadExactFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>ⓘNotable traits for ReadExactFuture<'_, R>
impl<'_, R> Future for ReadExactFuture<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Reads the exact number of bytes required to fill buf. Read more
Creates an adapter which will read at most limit bytes from it. Read more
Creates an adapter which will chain this stream with another. Read more
Boxes the reader and changes its type to dyn AsyncRead + Send + 'a. Read more
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized,
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized, fn seek(&mut self, pos: SeekFrom) -> SeekFuture<'_, Self>ⓘNotable traits for SeekFuture<'_, S>
impl<'_, S> Future for SeekFuture<'_, S> where
S: AsyncSeek + Unpin + ?Sized, type Output = Result<u64, Error>; where
Self: Unpin,
fn seek(&mut self, pos: SeekFrom) -> SeekFuture<'_, Self>ⓘNotable traits for SeekFuture<'_, S>
impl<'_, S> Future for SeekFuture<'_, S> where
S: AsyncSeek + Unpin + ?Sized, type Output = Result<u64, Error>; where
Self: Unpin, Seeks to a new position in a byte stream. Read more
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized, fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>
impl<'_, W> Future for WriteFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>
impl<'_, W> Future for WriteFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, Writes some bytes into the byte stream. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>
impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>
impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin, fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>
impl<'_, W> Future for WriteAllFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>
impl<'_, W> Future for WriteAllFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Writes an entire buffer into the byte stream. Read more
fn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>
impl<'_, W> Future for FlushFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>
impl<'_, W> Future for FlushFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Flushes the stream to ensure that all buffered contents reach their destination. Read more
fn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>
impl<'_, W> Future for CloseFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>
impl<'_, W> Future for CloseFuture<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin, Closes the writer. Read more
Boxes the writer and changes its type to dyn AsyncWrite + Send + 'a. Read more
Mutably borrows from an owned value. Read more
type Output = T
type Output = TShould always be Self
The inverse inclusion map: attempts to construct self from the equivalent element of its
superset. Read more
pub fn is_in_subset(&self) -> bool
pub fn is_in_subset(&self) -> boolChecks if self is actually part of its subset T (and can be converted to it).
pub fn to_subset_unchecked(&self) -> SS
pub fn to_subset_unchecked(&self) -> SSUse with care! Same as self.to_subset but without any property checks. Always succeeds.
pub fn from_subset(element: &SS) -> SP
pub fn from_subset(element: &SS) -> SPThe inclusion map: converts self to the equivalent element of its superset.
pub fn vzip(self) -> V