Struct futures_lite::io::Cursor[][src]

pub struct Cursor<T> { /* fields omitted */ }

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>[src]

pub fn new(inner: T) -> Cursor<T>[src]

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());

pub fn get_ref(&self) -> &T[src]

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();

pub fn get_mut(&mut self) -> &mut T[src]

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[src]

Unwraps 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]);

pub fn position(&self) -> u64[src]

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)[src]

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

impl<T> AsyncBufRead for Cursor<T> where
    T: AsRef<[u8]> + Unpin
[src]

impl<T> AsyncRead for Cursor<T> where
    T: AsRef<[u8]> + Unpin
[src]

impl<T> AsyncSeek for Cursor<T> where
    T: AsRef<[u8]> + Unpin
[src]

impl AsyncWrite for Cursor<&mut [u8]>[src]

impl AsyncWrite for Cursor<&mut Vec<u8>>[src]

impl AsyncWrite for Cursor<Vec<u8>>[src]

impl<T: Clone> Clone for Cursor<T>[src]

impl<T: Debug> Debug for Cursor<T>[src]

impl<T: Default> Default for Cursor<T>[src]

Auto Trait Implementations

impl<T> RefUnwindSafe for Cursor<T> where
    T: RefUnwindSafe

impl<T> Send for Cursor<T> where
    T: Send

impl<T> Sync for Cursor<T> where
    T: Sync

impl<T> Unpin for Cursor<T> where
    T: Unpin

impl<T> UnwindSafe for Cursor<T> where
    T: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<R> AsyncBufReadExt for R where
    R: AsyncBufRead + ?Sized
[src]

impl<R> AsyncReadExt for R where
    R: AsyncRead + ?Sized
[src]

impl<S> AsyncSeekExt for S where
    S: AsyncSeek + ?Sized
[src]

impl<W> AsyncWriteExt for W where
    W: AsyncWrite + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.