[][src]Struct smol::io::Cursor

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

Gives an in-memory buffer a cursor for reading and writing.

Examples

use futures_lite::*;

let mut bytes = b"hello".to_vec();
let mut cursor = io::Cursor::new(&mut bytes);

// Overwrite 'h' with 'H'.
cursor.write_all(b"H").await?;

// Move the cursor one byte forward.
cursor.seek(io::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::*;

let cursor = io::Cursor::new(Vec::<u8>::new());

pub fn get_ref(&self) -> &T

Important traits for &'_ mut F

impl<'_, F> Future for &'_ mut F where
    F: Unpin + Future + ?Sized
type Output = <F as Future>::Output;
[src]

Gets a reference to the underlying buffer.

Examples

use futures_lite::*;

let cursor = io::Cursor::new(Vec::<u8>::new());
let r = cursor.get_ref();

pub fn get_mut(&mut self) -> &mut T

Important traits for &'_ mut F

impl<'_, F> Future for &'_ mut F where
    F: Unpin + Future + ?Sized
type Output = <F as Future>::Output;
[src]

Gets a mutable reference to the underlying buffer.

Examples

use futures_lite::*;

let mut cursor = io::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::*;

let cursor = io::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::*;

let mut cursor = io::Cursor::new(b"hello");
assert_eq!(cursor.position(), 0);

cursor.seek(io::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::*;

let mut cursor = io::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<Vec<u8>>[src]

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

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

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

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

impl<T> Default for Cursor<T> where
    T: Default
[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<R> AsyncWriteExt for R where
    R: 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.