pub struct Cursor<T> { /* private fields */ }
Expand description
A Cursor
wraps an in-memory BufList
and provides it with a Seek
implementation.
Cursor
s allow BufList
s to implement Read
and BufRead
, allowing a BufList
to be
used anywhere you might use a reader or writer that does actual I/O.
The cursor may either own or borrow a BufList
: both Cursor<BufList>
and Cursor<&BufList>
are supported.
Optional features
tokio1
: With this feature enabled,Cursor
implements thetokio
crate’sAsyncSeek
,AsyncRead
andAsyncBufRead
.futures03
: With this feature enabled,Cursor
implements thefutures
crate’sAsyncSeek
,AsyncRead
andAsyncBufRead
.
Implementations§
source§impl<T: AsRef<BufList>> Cursor<T>
impl<T: AsRef<BufList>> Cursor<T>
sourcepub fn new(inner: T) -> Cursor<T> ⓘ
pub fn new(inner: T) -> Cursor<T> ⓘ
Creates a new cursor wrapping the provided BufList
.
Examples
use buf_list::{BufList, Cursor};
let cursor = Cursor::new(BufList::new());
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes this cursor, returning the underlying value.
Examples
use buf_list::{BufList, Cursor};
let cursor = Cursor::new(BufList::new());
let vec = cursor.into_inner();
sourcepub const fn get_ref(&self) -> &T
pub const fn get_ref(&self) -> &T
Gets a reference to the underlying value in this cursor.
Examples
use buf_list::{BufList, Cursor};
let cursor = Cursor::new(BufList::new());
let reference = cursor.get_ref();
sourcepub const fn position(&self) -> u64
pub const fn position(&self) -> u64
Returns the current position of this cursor.
Examples
use buf_list::{BufList, Cursor};
use std::io::prelude::*;
use std::io::SeekFrom;
let mut cursor = Cursor::new(BufList::from(&[1, 2, 3, 4, 5][..]));
assert_eq!(cursor.position(), 0);
cursor.seek(SeekFrom::Current(2)).unwrap();
assert_eq!(cursor.position(), 2);
cursor.seek(SeekFrom::Current(-1)).unwrap();
assert_eq!(cursor.position(), 1);
sourcepub fn set_position(&mut self, pos: u64)
pub fn set_position(&mut self, pos: u64)
Sets the position of this cursor.
Examples
use buf_list::{BufList, Cursor};
let mut cursor = Cursor::new(BufList::from(&[1, 2, 3, 4, 5][..]));
assert_eq!(cursor.position(), 0);
cursor.set_position(2);
assert_eq!(cursor.position(), 2);
cursor.set_position(4);
assert_eq!(cursor.position(), 4);
Trait Implementations§
source§impl<T: AsRef<BufList> + Unpin> AsyncBufRead for Cursor<T>
Available on crate feature futures03
only.
impl<T: AsRef<BufList> + Unpin> AsyncBufRead for Cursor<T>
Available on crate feature
futures03
only.source§impl<T: AsRef<BufList> + Unpin> AsyncBufRead for Cursor<T>
Available on crate feature tokio1
only.
impl<T: AsRef<BufList> + Unpin> AsyncBufRead for Cursor<T>
Available on crate feature
tokio1
only.source§impl<T: AsRef<BufList> + Unpin> AsyncRead for Cursor<T>
Available on crate feature futures03
only.
impl<T: AsRef<BufList> + Unpin> AsyncRead for Cursor<T>
Available on crate feature
futures03
only.source§impl<T: AsRef<BufList> + Unpin> AsyncRead for Cursor<T>
Available on crate feature tokio1
only.
impl<T: AsRef<BufList> + Unpin> AsyncRead for Cursor<T>
Available on crate feature
tokio1
only.source§impl<T: AsRef<BufList> + Unpin> AsyncSeek for Cursor<T>
Available on crate feature futures03
only.
impl<T: AsRef<BufList> + Unpin> AsyncSeek for Cursor<T>
Available on crate feature
futures03
only.source§impl<T: AsRef<BufList> + Unpin> AsyncSeek for Cursor<T>
Available on crate feature tokio1
only.
impl<T: AsRef<BufList> + Unpin> AsyncSeek for Cursor<T>
Available on crate feature
tokio1
only.source§impl<T: AsRef<BufList>> BufRead for Cursor<T>
impl<T: AsRef<BufList>> BufRead for Cursor<T>
source§fn fill_buf(&mut self) -> Result<&[u8]>
fn fill_buf(&mut self) -> Result<&[u8]>
Returns the contents of the internal buffer, filling it with more data
from the inner reader if it is empty. Read more
source§fn consume(&mut self, amt: usize)
fn consume(&mut self, amt: usize)
Tells this buffer that
amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read moresource§fn has_data_left(&mut self) -> Result<bool, Error>
fn has_data_left(&mut self) -> Result<bool, Error>
🔬This is a nightly-only experimental API. (
buf_read_has_data_left
)Check if the underlying
Read
has any data left to be read. Read more1.0.0 · source§fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
fn read_until(
&mut self,
byte: u8,
buf: &mut Vec<u8, Global>
) -> Result<usize, Error>
1.0.0 · source§fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_line(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until a newline (the
0xA
byte) is reached, and append
them to the provided String
buffer. Read moresource§impl<T: AsRef<BufList>> Read for Cursor<T>
impl<T: AsRef<BufList>> Read for Cursor<T>
source§fn read(&mut self, buf: &mut [u8]) -> Result<usize>
fn read(&mut self, buf: &mut [u8]) -> Result<usize>
Pull some bytes from this source into the specified buffer, returning
how many bytes were read. Read more
source§fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize>
Like
read
, except that it reads into a slice of buffers. Read moresource§fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>
Read the exact number of bytes required to fill
buf
. Read moresource§fn is_read_vectored(&self) -> bool
fn is_read_vectored(&self) -> bool
🔬This is a nightly-only experimental API. (
can_vector
)1.0.0 · source§fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
fn read_to_end(&mut self, buf: &mut Vec<u8, Global>) -> Result<usize, Error>
Read all bytes until EOF in this source, placing them into
buf
. Read more1.0.0 · source§fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
fn read_to_string(&mut self, buf: &mut String) -> Result<usize, Error>
Read all bytes until EOF in this source, appending them to
buf
. Read moresource§fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf(&mut self, buf: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Pull some bytes from this source into the specified buffer. Read more
source§fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
fn read_buf_exact(&mut self, cursor: BorrowedCursor<'_>) -> Result<(), Error>
🔬This is a nightly-only experimental API. (
read_buf
)Read the exact number of bytes required to fill
cursor
. Read more1.0.0 · source§fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
fn by_ref(&mut self) -> &mut Selfwhere
Self: Sized,
Creates a “by reference” adaptor for this instance of
Read
. Read moresource§impl<T: AsRef<BufList>> Seek for Cursor<T>
impl<T: AsRef<BufList>> Seek for Cursor<T>
source§fn seek(&mut self, style: SeekFrom) -> Result<u64>
fn seek(&mut self, style: SeekFrom) -> Result<u64>
Seek to an offset, in bytes, in a stream. Read more
source§fn stream_position(&mut self) -> Result<u64>
fn stream_position(&mut self) -> Result<u64>
Returns the current seek position from the start of the stream. Read more
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§
source§impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
impl<R> AsyncBufReadExt for Rwhere
R: AsyncBufRead + ?Sized,
source§fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntil<'a, Self>where
Self: Unpin,
fn read_until<'a>(
&'a mut self,
byte: u8,
buf: &'a mut Vec<u8, Global>
) -> ReadUntil<'a, Self>where
Self: Unpin,
source§fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self>where
Self: Unpin,
fn read_line<'a>(&'a mut self, buf: &'a mut String) -> ReadLine<'a, Self>where
Self: Unpin,
Reads all bytes until a newline (the 0xA byte) is reached, and append
them to the provided buffer. Read more
source§fn split(self, byte: u8) -> Split<Self>where
Self: Sized + Unpin,
fn split(self, byte: u8) -> Split<Self>where
Self: Sized + Unpin,
Returns a stream of the contents of this reader split on the byte
byte
. Read moresource§fn fill_buf(&mut self) -> FillBuf<'_, Self>where
Self: Unpin,
fn fill_buf(&mut self) -> FillBuf<'_, Self>where
Self: Unpin,
Returns the contents of the internal buffer, filling it with more
data from the inner reader if it is empty. Read more
source§impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
impl<R> AsyncReadExt for Rwhere
R: AsyncRead + ?Sized,
source§fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
fn read<'a>(&'a mut self, buf: &'a mut [u8]) -> Read<'a, Self>where
Self: Unpin,
Pulls some bytes from this source into the specified buffer,
returning how many bytes were read. Read more
source§fn read_buf<B, 'a>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>where
Self: Sized + Unpin,
B: BufMut,
fn read_buf<B, 'a>(&'a mut self, buf: &'a mut B) -> ReadBuf<'a, Self, B>where
Self: Sized + Unpin,
B: BufMut,
Pulls some bytes from this source into the specified buffer,
advancing the buffer’s internal cursor. Read more
source§fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
fn read_exact<'a>(&'a mut self, buf: &'a mut [u8]) -> ReadExact<'a, Self>where
Self: Unpin,
Reads the exact number of bytes required to fill
buf
. Read moresource§fn read_u8<'a>(&'a mut self) -> ReadU8<&'a mut Self>where
Self: Unpin,
fn read_u8<'a>(&'a mut self) -> ReadU8<&'a mut Self>where
Self: Unpin,
Reads an unsigned 8 bit integer from the underlying reader. Read more
source§fn read_i8<'a>(&'a mut self) -> ReadI8<&'a mut Self>where
Self: Unpin,
fn read_i8<'a>(&'a mut self) -> ReadI8<&'a mut Self>where
Self: Unpin,
Reads a signed 8 bit integer from the underlying reader. Read more
source§fn read_u16<'a>(&'a mut self) -> ReadU16<&'a mut Self>where
Self: Unpin,
fn read_u16<'a>(&'a mut self) -> ReadU16<&'a mut Self>where
Self: Unpin,
Reads an unsigned 16-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_i16<'a>(&'a mut self) -> ReadI16<&'a mut Self>where
Self: Unpin,
fn read_i16<'a>(&'a mut self) -> ReadI16<&'a mut Self>where
Self: Unpin,
Reads a signed 16-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_u32<'a>(&'a mut self) -> ReadU32<&'a mut Self>where
Self: Unpin,
fn read_u32<'a>(&'a mut self) -> ReadU32<&'a mut Self>where
Self: Unpin,
Reads an unsigned 32-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_i32<'a>(&'a mut self) -> ReadI32<&'a mut Self>where
Self: Unpin,
fn read_i32<'a>(&'a mut self) -> ReadI32<&'a mut Self>where
Self: Unpin,
Reads a signed 32-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_u64<'a>(&'a mut self) -> ReadU64<&'a mut Self>where
Self: Unpin,
fn read_u64<'a>(&'a mut self) -> ReadU64<&'a mut Self>where
Self: Unpin,
Reads an unsigned 64-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_i64<'a>(&'a mut self) -> ReadI64<&'a mut Self>where
Self: Unpin,
fn read_i64<'a>(&'a mut self) -> ReadI64<&'a mut Self>where
Self: Unpin,
Reads an signed 64-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_u128<'a>(&'a mut self) -> ReadU128<&'a mut Self>where
Self: Unpin,
fn read_u128<'a>(&'a mut self) -> ReadU128<&'a mut Self>where
Self: Unpin,
Reads an unsigned 128-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_i128<'a>(&'a mut self) -> ReadI128<&'a mut Self>where
Self: Unpin,
fn read_i128<'a>(&'a mut self) -> ReadI128<&'a mut Self>where
Self: Unpin,
Reads an signed 128-bit integer in big-endian order from the
underlying reader. Read more
source§fn read_f32<'a>(&'a mut self) -> ReadF32<&'a mut Self>where
Self: Unpin,
fn read_f32<'a>(&'a mut self) -> ReadF32<&'a mut Self>where
Self: Unpin,
Reads an 32-bit floating point type in big-endian order from the
underlying reader. Read more
source§fn read_f64<'a>(&'a mut self) -> ReadF64<&'a mut Self>where
Self: Unpin,
fn read_f64<'a>(&'a mut self) -> ReadF64<&'a mut Self>where
Self: Unpin,
Reads an 64-bit floating point type in big-endian order from the
underlying reader. Read more
source§fn read_u16_le<'a>(&'a mut self) -> ReadU16Le<&'a mut Self>where
Self: Unpin,
fn read_u16_le<'a>(&'a mut self) -> ReadU16Le<&'a mut Self>where
Self: Unpin,
Reads an unsigned 16-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_i16_le<'a>(&'a mut self) -> ReadI16Le<&'a mut Self>where
Self: Unpin,
fn read_i16_le<'a>(&'a mut self) -> ReadI16Le<&'a mut Self>where
Self: Unpin,
Reads a signed 16-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_u32_le<'a>(&'a mut self) -> ReadU32Le<&'a mut Self>where
Self: Unpin,
fn read_u32_le<'a>(&'a mut self) -> ReadU32Le<&'a mut Self>where
Self: Unpin,
Reads an unsigned 32-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_i32_le<'a>(&'a mut self) -> ReadI32Le<&'a mut Self>where
Self: Unpin,
fn read_i32_le<'a>(&'a mut self) -> ReadI32Le<&'a mut Self>where
Self: Unpin,
Reads a signed 32-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_u64_le<'a>(&'a mut self) -> ReadU64Le<&'a mut Self>where
Self: Unpin,
fn read_u64_le<'a>(&'a mut self) -> ReadU64Le<&'a mut Self>where
Self: Unpin,
Reads an unsigned 64-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_i64_le<'a>(&'a mut self) -> ReadI64Le<&'a mut Self>where
Self: Unpin,
fn read_i64_le<'a>(&'a mut self) -> ReadI64Le<&'a mut Self>where
Self: Unpin,
Reads an signed 64-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_u128_le<'a>(&'a mut self) -> ReadU128Le<&'a mut Self>where
Self: Unpin,
fn read_u128_le<'a>(&'a mut self) -> ReadU128Le<&'a mut Self>where
Self: Unpin,
Reads an unsigned 128-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_i128_le<'a>(&'a mut self) -> ReadI128Le<&'a mut Self>where
Self: Unpin,
fn read_i128_le<'a>(&'a mut self) -> ReadI128Le<&'a mut Self>where
Self: Unpin,
Reads an signed 128-bit integer in little-endian order from the
underlying reader. Read more
source§fn read_f32_le<'a>(&'a mut self) -> ReadF32Le<&'a mut Self>where
Self: Unpin,
fn read_f32_le<'a>(&'a mut self) -> ReadF32Le<&'a mut Self>where
Self: Unpin,
Reads an 32-bit floating point type in little-endian order from the
underlying reader. Read more
source§fn read_f64_le<'a>(&'a mut self) -> ReadF64Le<&'a mut Self>where
Self: Unpin,
fn read_f64_le<'a>(&'a mut self) -> ReadF64Le<&'a mut Self>where
Self: Unpin,
Reads an 64-bit floating point type in little-endian order from the
underlying reader. Read more
source§fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEnd<'a, Self>where
Self: Unpin,
fn read_to_end<'a>(
&'a mut self,
buf: &'a mut Vec<u8, Global>
) -> ReadToEnd<'a, Self>where
Self: Unpin,
Reads all bytes until EOF in this source, placing them into
buf
. Read moresource§impl<S> AsyncSeekExt for Swhere
S: AsyncSeek + ?Sized,
impl<S> AsyncSeekExt for Swhere
S: AsyncSeek + ?Sized,
source§fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>where
Self: Unpin,
fn seek(&mut self, pos: SeekFrom) -> Seek<'_, Self>where
Self: Unpin,
Creates a future which will seek an IO object, and then yield the
new position in the object and the object itself. Read more
source§fn rewind(&mut self) -> Seek<'_, Self>where
Self: Unpin,
fn rewind(&mut self) -> Seek<'_, Self>where
Self: Unpin,
Creates a future which will rewind to the beginning of the stream. Read more
source§fn stream_position(&mut self) -> Seek<'_, Self>where
Self: Unpin,
fn stream_position(&mut self) -> Seek<'_, Self>where
Self: Unpin,
Creates a future which will return the current seek position from the
start of the stream. Read more