Struct futures::io::Cursor [−][src]
pub struct Cursor<T> { /* fields omitted */ }Expand description
A Cursor wraps an in-memory buffer and provides it with a
AsyncSeek implementation.
Cursors are used with in-memory buffers, anything implementing
AsRef<[u8]>, to allow them to implement AsyncRead and/or AsyncWrite,
allowing these buffers to be used anywhere you might use a reader or writer
that does actual I/O.
This library implements some I/O traits on various types which
are commonly used as a buffer, like Cursor<Vec<u8>> and
Cursor<&[u8]>.
Implementations
Creates a new cursor wrapping the provided underlying in-memory buffer.
Cursor initial position is 0 even if underlying buffer (e.g., Vec)
is not empty. So writing to cursor starts with overwriting Vec
content, not with appending to it.
Examples
use futures::io::Cursor;
let buff = Cursor::new(Vec::new());Consumes this cursor, returning the underlying value.
Examples
use futures::io::Cursor;
let buff = Cursor::new(Vec::new());
let vec = buff.into_inner();Gets a reference to the underlying value in this cursor.
Examples
use futures::io::Cursor;
let buff = Cursor::new(Vec::new());
let reference = buff.get_ref();Gets a mutable reference to the underlying value in this cursor.
Care should be taken to avoid modifying the internal I/O state of the underlying value as it may corrupt this cursor’s position.
Examples
use futures::io::Cursor;
let mut buff = Cursor::new(Vec::new());
let reference = buff.get_mut();Returns the current position of this cursor.
Examples
use futures::io::{AsyncSeekExt, Cursor, SeekFrom};
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.seek(SeekFrom::Current(2)).await?;
assert_eq!(buff.position(), 2);
buff.seek(SeekFrom::Current(-1)).await?;
assert_eq!(buff.position(), 1);Sets the position of this cursor.
Examples
use futures::io::Cursor;
let mut buff = Cursor::new(vec![1, 2, 3, 4, 5]);
assert_eq!(buff.position(), 0);
buff.set_position(2);
assert_eq!(buff.position(), 2);
buff.set_position(4);
assert_eq!(buff.position(), 4);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
Auto Trait Implementations
impl<T> RefUnwindSafe for Cursor<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Cursor<T> where
T: UnwindSafe,
Blanket Implementations
Creates a future which will wait for a non-empty buffer to be available from this I/O object or EOF to be reached. Read more
A convenience for calling AsyncBufRead::consume on Unpin IO types. Read more
Creates a future which will read all the bytes associated with this I/O
object into buf until the delimiter byte or EOF is reached.
This method is the async equivalent to BufRead::read_until. Read more
Creates a future which will read all the bytes associated with this I/O
object into buf until a newline (the 0xA byte) or EOF is reached,
This method is the async equivalent to BufRead::read_line. Read more
Returns a stream over the lines of this reader.
This method is the async equivalent to BufRead::lines. Read more
Creates an adaptor which will chain this stream with another. Read more
Tries to read some bytes directly into the given buf in asynchronous
manner, returning a future type. Read more
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self>ⓘNotable traits for ReadVectored<'_, R>impl<'_, R> Future for ReadVectored<'_, 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>]
) -> ReadVectored<'a, Self>ⓘNotable traits for ReadVectored<'_, R>impl<'_, R> Future for ReadVectored<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
impl<'_, R> Future for ReadVectored<'_, R> where
R: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;Creates a future which will read from the AsyncRead into bufs using vectored
IO operations. Read more
Creates a future which will read exactly enough bytes to fill buf,
returning an error if end of file (EOF) is hit sooner. Read more
Creates a future which will read all the bytes from this AsyncRead. Read more
fn read_to_string(&'a mut self, buf: &'a mut String) -> ReadToString<'a, Self>ⓘNotable traits for ReadToString<'_, A>impl<'_, A> Future for ReadToString<'_, A> where
A: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn read_to_string(&'a mut self, buf: &'a mut String) -> ReadToString<'a, Self>ⓘNotable traits for ReadToString<'_, A>impl<'_, A> Future for ReadToString<'_, A> where
A: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
impl<'_, A> Future for ReadToString<'_, A> where
A: AsyncRead + Unpin + ?Sized, type Output = Result<usize, Error>;Creates a future which will read all the bytes from this AsyncRead. Read more
Helper method for splitting this read/write object into two halves. Read more
Creates an AsyncRead adapter which will read at most limit bytes
from the underlying reader. Read more
Wraps an AsyncRead in a compatibility wrapper that allows it to be
used as a futures 0.1 / tokio-io 0.1 AsyncRead. If the wrapped type
implements AsyncWrite as well, the result will also implement the
futures 0.1 / tokio 0.1 AsyncWrite trait. Read more
Creates a future which will entirely flush this AsyncWrite. Read more
Creates a future which will entirely close this AsyncWrite.
Creates a future which will write bytes from buf into the object. Read more
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<'_, W> Future for WriteVectored<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<'_, W> Future for WriteVectored<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>; where
Self: Unpin,
impl<'_, W> Future for WriteVectored<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<usize, Error>;Creates a future which will write bytes from bufs into the object using vectored
IO operations. Read more
Write data into this object. Read more
fn write_all_vectored(
&'a mut self,
bufs: &'a mut [IoSlice<'a>]
) -> WriteAllVectored<'a, Self>ⓘNotable traits for WriteAllVectored<'_, W>impl<'_, W> Future for WriteAllVectored<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
fn write_all_vectored(
&'a mut self,
bufs: &'a mut [IoSlice<'a>]
) -> WriteAllVectored<'a, Self>ⓘNotable traits for WriteAllVectored<'_, W>impl<'_, W> Future for WriteAllVectored<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>; where
Self: Unpin,
impl<'_, W> Future for WriteAllVectored<'_, W> where
W: AsyncWrite + Unpin + ?Sized, type Output = Result<(), Error>;Attempts to write multiple buffers into this writer. Read more
Wraps an AsyncWrite in a compatibility wrapper that allows it to be
used as a futures 0.1 / tokio-io 0.1 AsyncWrite.
Requires the io-compat feature to enable. Read more
Mutably borrows from an owned value. Read more