Struct Cursor
struct Cursor<T> { ... }
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
impl<T> Cursor<T>
fn new(inner: T) -> SelfCreates a new cursor wrapping the provided underlying in-memory buffer.
Cursor initial position is
0even if underlying buffer (e.g.,Vec) is not empty. So writing to cursor starts with overwritingVeccontent, not with appending to it.Examples
use Cursor; let buff = new; # # force_inference;fn into_inner(self: Self) -> TConsumes this cursor, returning the underlying value.
Examples
use Cursor; let buff = new; # # force_inference; let vec = buff.into_inner;fn get_ref(self: &Self) -> &TGets a reference to the underlying value in this cursor.
Examples
use Cursor; let buff = new; # # force_inference; let reference = buff.get_ref;fn get_mut(self: &mut Self) -> &mut TGets 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 Cursor; let mut buff = new; # # force_inference; let reference = buff.get_mut;fn position(self: &Self) -> u64Returns the current position of this cursor.
Examples
# block_on.unwrap;fn set_position(self: &mut Self, pos: u64)Sets the position of this cursor.
Examples
use Cursor; let mut buff = new; assert_eq!; buff.set_position; assert_eq!; buff.set_position; assert_eq!;
impl AsyncWrite for Cursor<&mut Vec<u8>>
fn poll_write(self: Pin<&mut Self>, _: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>fn poll_write_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize>>fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
impl AsyncWrite for Cursor<&mut [u8]>
fn poll_write(self: Pin<&mut Self>, _: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>fn poll_write_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize>>fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
impl AsyncWrite for Cursor<Box<[u8]>>
fn poll_write(self: Pin<&mut Self>, _: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>fn poll_write_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize>>fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
impl AsyncWrite for Cursor<Vec<u8>>
fn poll_write(self: Pin<&mut Self>, _: &mut Context<'_>, buf: &[u8]) -> Poll<Result<usize>>fn poll_write_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &[IoSlice<'_>]) -> Poll<Result<usize>>fn poll_flush(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<()>>fn poll_close(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Result<()>>
impl<R> AsyncBufReadExt for Cursor<T>
impl<R> AsyncReadExt for Cursor<T>
impl<S> AsyncSeekExt for Cursor<T>
impl<T> Any for Cursor<T>
fn type_id(self: &Self) -> TypeId
impl<T> AsyncBufRead for Cursor<T>
fn poll_fill_buf(self: Pin<&mut Self>, _: &mut Context<'_>) -> Poll<Result<&[u8]>>fn consume(self: Pin<&mut Self>, amt: usize)
impl<T> AsyncSeek for Cursor<T>
fn poll_seek(self: Pin<&mut Self>, _: &mut Context<'_>, pos: SeekFrom) -> Poll<Result<u64>>
impl<T> Borrow for Cursor<T>
fn borrow(self: &Self) -> &T
impl<T> BorrowMut for Cursor<T>
fn borrow_mut(self: &mut Self) -> &mut T
impl<T> CloneToUninit for Cursor<T>
unsafe fn clone_to_uninit(self: &Self, dest: *mut u8)
impl<T> Freeze for Cursor<T>
impl<T> From for Cursor<T>
fn from(t: T) -> TReturns the argument unchanged.
impl<T> RefUnwindSafe for Cursor<T>
impl<T> Send for Cursor<T>
impl<T> Sync for Cursor<T>
impl<T> ToOwned for Cursor<T>
fn to_owned(self: &Self) -> Tfn clone_into(self: &Self, target: &mut T)
impl<T> Unpin for Cursor<T>
impl<T> UnsafeUnpin for Cursor<T>
impl<T> UnwindSafe for Cursor<T>
impl<T, U> Into for Cursor<T>
fn into(self: Self) -> UCalls
U::from(self).That is, this conversion is whatever the implementation of
[From]<T> for Uchooses to do.
impl<T, U> TryFrom for Cursor<T>
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
impl<T, U> TryInto for Cursor<T>
fn try_into(self: Self) -> Result<U, <U as TryFrom<T>>::Error>
impl<T: $crate::clone::Clone> Clone for Cursor<T>
fn clone(self: &Self) -> Cursor<T>
impl<T: $crate::default::Default> Default for Cursor<T>
fn default() -> Cursor<T>
impl<T: $crate::fmt::Debug> Debug for Cursor<T>
fn fmt(self: &Self, f: &mut Formatter<'_>) -> Result
impl<T: AsRef<[u8]> + Unpin> AsyncRead for Cursor<T>
fn poll_read(self: Pin<&mut Self>, _cx: &mut Context<'_>, buf: &mut [u8]) -> Poll<Result<usize>>fn poll_read_vectored(self: Pin<&mut Self>, _: &mut Context<'_>, bufs: &mut [IoSliceMut<'_>]) -> Poll<Result<usize>>