[−][src]Struct smol::io::Cursor
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ⓘ
[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ⓘ
[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]
T: AsRef<[u8]> + Unpin,
fn poll_fill_buf(
self: Pin<&mut Cursor<T>>,
&mut Context<'_>
) -> Poll<Result<&[u8], Error>>
[src]
self: Pin<&mut Cursor<T>>,
&mut Context<'_>
) -> Poll<Result<&[u8], Error>>
fn consume(self: Pin<&mut Cursor<T>>, amt: usize)
[src]
impl<T> AsyncRead for Cursor<T> where
T: AsRef<[u8]> + Unpin,
[src]
T: AsRef<[u8]> + Unpin,
fn poll_read(
self: Pin<&mut Cursor<T>>,
_cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Cursor<T>>,
_cx: &mut Context<'_>,
buf: &mut [u8]
) -> Poll<Result<usize, Error>>
fn poll_read_vectored(
self: Pin<&mut Cursor<T>>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Cursor<T>>,
&mut Context<'_>,
bufs: &mut [IoSliceMut<'_>]
) -> Poll<Result<usize, Error>>
impl<T> AsyncSeek for Cursor<T> where
T: AsRef<[u8]> + Unpin,
[src]
T: AsRef<[u8]> + Unpin,
fn poll_seek(
self: Pin<&mut Cursor<T>>,
&mut Context<'_>,
pos: SeekFrom
) -> Poll<Result<u64, Error>>
[src]
self: Pin<&mut Cursor<T>>,
&mut Context<'_>,
pos: SeekFrom
) -> Poll<Result<u64, Error>>
impl AsyncWrite for Cursor<Vec<u8>>
[src]
fn poll_write(
self: Pin<&mut Cursor<Vec<u8>>>,
&mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Cursor<Vec<u8>>>,
&mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_close(
self: Pin<&mut Cursor<Vec<u8>>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Cursor<Vec<u8>>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_flush(
self: Pin<&mut Cursor<Vec<u8>>>,
&mut Context<'_>
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Cursor<Vec<u8>>>,
&mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
impl<'_> AsyncWrite for Cursor<&'_ mut Vec<u8>>
[src]
fn poll_write(
self: Pin<&mut Cursor<&'_ mut Vec<u8>>>,
&mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Cursor<&'_ mut Vec<u8>>>,
&mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_close(
self: Pin<&mut Cursor<&'_ mut Vec<u8>>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Cursor<&'_ mut Vec<u8>>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_flush(
self: Pin<&mut Cursor<&'_ mut Vec<u8>>>,
&mut Context<'_>
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Cursor<&'_ mut Vec<u8>>>,
&mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_write_vectored(
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Self>,
cx: &mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
impl<'_> AsyncWrite for Cursor<&'_ mut [u8]>
[src]
fn poll_write(
self: Pin<&mut Cursor<&'_ mut [u8]>>,
&mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Cursor<&'_ mut [u8]>>,
&mut Context<'_>,
buf: &[u8]
) -> Poll<Result<usize, Error>>
fn poll_write_vectored(
self: Pin<&mut Cursor<&'_ mut [u8]>>,
&mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
[src]
self: Pin<&mut Cursor<&'_ mut [u8]>>,
&mut Context<'_>,
bufs: &[IoSlice<'_>]
) -> Poll<Result<usize, Error>>
fn poll_flush(
self: Pin<&mut Cursor<&'_ mut [u8]>>,
&mut Context<'_>
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Cursor<&'_ mut [u8]>>,
&mut Context<'_>
) -> Poll<Result<(), Error>>
fn poll_close(
self: Pin<&mut Cursor<&'_ mut [u8]>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
[src]
self: Pin<&mut Cursor<&'_ mut [u8]>>,
cx: &mut Context<'_>
) -> Poll<Result<(), Error>>
impl<T> Clone for Cursor<T> where
T: Clone,
[src]
T: Clone,
impl<T> Debug for Cursor<T> where
T: Debug,
[src]
T: Debug,
impl<T> Default for Cursor<T> where
T: Default,
[src]
T: Default,
Auto Trait Implementations
impl<T> RefUnwindSafe for Cursor<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Cursor<T> where
T: Send,
T: Send,
impl<T> Sync for Cursor<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Cursor<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Cursor<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<R> AsyncBufReadExt for R where
R: AsyncBufRead + ?Sized,
[src]
R: AsyncBufRead + ?Sized,
fn read_until(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self>ⓘNotable traits for ReadUntilFuture<'_, R>
impl<'_, R> Future for ReadUntilFuture<'_, R> where
R: Unpin + AsyncBufRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8>
) -> ReadUntilFuture<'a, Self>ⓘ
Notable traits for ReadUntilFuture<'_, R>
impl<'_, R> Future for ReadUntilFuture<'_, R> where
R: Unpin + AsyncBufRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_line(&'a mut self, buf: &'a mut String) -> ReadLineFuture<'a, Self>ⓘNotable traits for ReadLineFuture<'_, R>
impl<'_, R> Future for ReadLineFuture<'_, R> where
R: Unpin + AsyncBufRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Notable traits for ReadLineFuture<'_, R>
impl<'_, R> Future for ReadLineFuture<'_, R> where
R: Unpin + AsyncBufRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn lines(self) -> Lines<Self> where
Self: Unpin,
[src]
Self: Unpin,
fn split(self, byte: u8) -> Split<Self>
[src]
impl<R> AsyncReadExt for R where
R: AsyncRead + ?Sized,
[src]
R: AsyncRead + ?Sized,
fn read(&'a mut self, buf: &'a mut [u8]) -> ReadFuture<'a, Self>ⓘNotable traits for ReadFuture<'_, R>
impl<'_, R> Future for ReadFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Notable traits for ReadFuture<'_, R>
impl<'_, R> Future for ReadFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_vectored(
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘNotable traits for ReadVectoredFuture<'_, R>
impl<'_, R> Future for ReadVectoredFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a mut [IoSliceMut<'a>]
) -> ReadVectoredFuture<'a, Self>ⓘ
Notable traits for ReadVectoredFuture<'_, R>
impl<'_, R> Future for ReadVectoredFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_to_end(&'a mut self, buf: &'a mut Vec<u8>) -> ReadToEndFuture<'a, Self>ⓘNotable traits for ReadToEndFuture<'_, R>
impl<'_, R> Future for ReadToEndFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Notable traits for ReadToEndFuture<'_, R>
impl<'_, R> Future for ReadToEndFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_to_string(
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘNotable traits for ReadToStringFuture<'_, R>
impl<'_, R> Future for ReadToStringFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
buf: &'a mut String
) -> ReadToStringFuture<'a, Self>ⓘ
Notable traits for ReadToStringFuture<'_, R>
impl<'_, R> Future for ReadToStringFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn read_exact(&'a mut self, buf: &'a mut [u8]) -> ReadExactFuture<'a, Self>ⓘNotable traits for ReadExactFuture<'_, R>
impl<'_, R> Future for ReadExactFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Notable traits for ReadExactFuture<'_, R>
impl<'_, R> Future for ReadExactFuture<'_, R> where
R: Unpin + AsyncRead + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
fn take(self, limit: u64) -> Take<Self>
[src]
fn bytes(self) -> Bytes<Self>
[src]
fn chain<R>(self, next: R) -> Chain<Self, R> where
R: AsyncRead,
[src]
R: AsyncRead,
impl<S> AsyncSeekExt for S where
S: AsyncSeek + ?Sized,
[src]
S: AsyncSeek + ?Sized,
fn seek(&mut self, pos: SeekFrom) -> SeekFuture<'_, Self>ⓘNotable traits for SeekFuture<'_, S>
impl<'_, S> Future for SeekFuture<'_, S> where
S: Unpin + AsyncSeek + ?Sized, type Output = Result<u64, Error>;
where
Self: Unpin,
[src]
Notable traits for SeekFuture<'_, S>
impl<'_, S> Future for SeekFuture<'_, S> where
S: Unpin + AsyncSeek + ?Sized, type Output = Result<u64, Error>;
Self: Unpin,
impl<W> AsyncWriteExt for W where
W: AsyncWrite + ?Sized,
[src]
W: AsyncWrite + ?Sized,
fn write(&'a mut self, buf: &'a [u8]) -> WriteFuture<'a, Self>ⓘNotable traits for WriteFuture<'_, W>
impl<'_, W> Future for WriteFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
Notable traits for WriteFuture<'_, W>
impl<'_, W> Future for WriteFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn write_vectored(
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘNotable traits for WriteVectoredFuture<'_, W>
impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
where
Self: Unpin,
[src]
&'a mut self,
bufs: &'a [IoSlice<'a>]
) -> WriteVectoredFuture<'a, Self>ⓘ
Notable traits for WriteVectoredFuture<'_, W>
impl<'_, W> Future for WriteVectoredFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<usize, Error>;
Self: Unpin,
fn write_all(&'a mut self, buf: &'a [u8]) -> WriteAllFuture<'a, Self>ⓘNotable traits for WriteAllFuture<'_, W>
impl<'_, W> Future for WriteAllFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Notable traits for WriteAllFuture<'_, W>
impl<'_, W> Future for WriteAllFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
fn flush(&mut self) -> FlushFuture<'_, Self>ⓘNotable traits for FlushFuture<'_, W>
impl<'_, W> Future for FlushFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Notable traits for FlushFuture<'_, W>
impl<'_, W> Future for FlushFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
fn close(&mut self) -> CloseFuture<'_, Self>ⓘNotable traits for CloseFuture<'_, W>
impl<'_, W> Future for CloseFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
where
Self: Unpin,
[src]
Notable traits for CloseFuture<'_, W>
impl<'_, W> Future for CloseFuture<'_, W> where
W: Unpin + AsyncWrite + ?Sized, type Output = Result<(), Error>;
Self: Unpin,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut Tⓘ
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,