Struct futures_util::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.
Cursor
s 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
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>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self>ⓘNotable traits for ReadVectored<'_, R>impl<R: AsyncRead + ?Sized + Unpin> Future for ReadVectored<'_, R> type Output = Result<usize>;
where
Self: Unpin,
fn read_vectored<'a>(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectored<'a, Self>ⓘNotable traits for ReadVectored<'_, R>impl<R: AsyncRead + ?Sized + Unpin> Future for ReadVectored<'_, R> type Output = Result<usize>;
where
Self: Unpin,
impl<R: AsyncRead + ?Sized + Unpin> Future for ReadVectored<'_, R> type Output = Result<usize>;
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>(
&'a mut self,
buf: &'a mut String
) -> ReadToString<'a, Self>ⓘNotable traits for ReadToString<'_, A>impl<A> Future for ReadToString<'_, A> where
A: AsyncRead + ?Sized + Unpin, type Output = Result<usize>;
where
Self: Unpin,
fn read_to_string<'a>(
&'a mut self,
buf: &'a mut String
) -> ReadToString<'a, Self>ⓘNotable traits for ReadToString<'_, A>impl<A> Future for ReadToString<'_, A> where
A: AsyncRead + ?Sized + Unpin, type Output = Result<usize>;
where
Self: Unpin,
impl<A> Future for ReadToString<'_, A> where
A: AsyncRead + ?Sized + Unpin, type Output = Result<usize>;
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 a future which will seek an IO object, and then yield the new position in the object and the object itself. 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>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteVectored<'_, W> type Output = Result<usize>;
where
Self: Unpin,
fn write_vectored<'a>(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectored<'a, Self>ⓘNotable traits for WriteVectored<'_, W>impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteVectored<'_, W> type Output = Result<usize>;
where
Self: Unpin,
impl<W: AsyncWrite + ?Sized + Unpin> Future for WriteVectored<'_, W> type Output = Result<usize>;
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
Mutably borrows from an owned value. Read more