Struct pw_stream::Cursor

source ·
pub struct Cursor<T>
where T: AsRef<[u8]>,
{ /* private fields */ }
Expand description

Wraps an AsRef<u8> in a container implementing Read, Write, and Seek.

Write support requires the inner type also implement AsMut<u8>.

Implementations§

source§

impl<T: AsRef<[u8]>> Cursor<T>

source

pub fn new(inner: T) -> Self

Create a new Cursor wrapping inner with an initial position of 0.

Semantics match std::io::Cursor::new().

source

pub fn into_inner(self) -> T

Consumes the cursor and returns the inner wrapped data.

source

pub fn remaining(&self) -> usize

Returns the number of remaining bytes in the Cursor.

source

pub fn len(&self) -> usize

Returns the total length of the Cursor.

source

pub fn position(&self) -> usize

Returns current IO position of the Cursor.

Trait Implementations§

source§

impl<T: AsRef<[u8]>> Read for Cursor<T>

source§

fn read(&mut self, buf: &mut [u8]) -> Result<usize>

Read from a stream into a buffer. Read more
source§

fn read_exact(&mut self, buf: &mut [u8]) -> Result<()>

Read exactly enough bytes to fill the buffer. Read more
source§

impl<T: AsRef<[u8]>> ReadInteger for Cursor<T>

source§

fn read_i8_le(&mut self) -> Result<i8>

Reads a little-endian i8 returning it’s value or an Error. Read more
source§

fn read_u8_le(&mut self) -> Result<u8>

Reads a little-endian u8 returning it’s value or an Error. Read more
source§

fn read_i8_be(&mut self) -> Result<i8>

Reads a big-endian i8 returning it’s value or an Error. Read more
source§

fn read_u8_be(&mut self) -> Result<u8>

Reads a big-endian u8 returning it’s value or an Error. Read more
source§

fn read_i16_le(&mut self) -> Result<i16>

Reads a little-endian i16 returning it’s value or an Error. Read more
source§

fn read_u16_le(&mut self) -> Result<u16>

Reads a little-endian u16 returning it’s value or an Error. Read more
source§

fn read_i16_be(&mut self) -> Result<i16>

Reads a big-endian i16 returning it’s value or an Error. Read more
source§

fn read_u16_be(&mut self) -> Result<u16>

Reads a big-endian u16 returning it’s value or an Error. Read more
source§

fn read_i32_le(&mut self) -> Result<i32>

Reads a little-endian i32 returning it’s value or an Error. Read more
source§

fn read_u32_le(&mut self) -> Result<u32>

Reads a little-endian u32 returning it’s value or an Error. Read more
source§

fn read_i32_be(&mut self) -> Result<i32>

Reads a big-endian i32 returning it’s value or an Error. Read more
source§

fn read_u32_be(&mut self) -> Result<u32>

Reads a big-endian u32 returning it’s value or an Error. Read more
source§

fn read_i64_le(&mut self) -> Result<i64>

Reads a little-endian i64 returning it’s value or an Error. Read more
source§

fn read_u64_le(&mut self) -> Result<u64>

Reads a little-endian u64 returning it’s value or an Error. Read more
source§

fn read_i64_be(&mut self) -> Result<i64>

Reads a big-endian i64 returning it’s value or an Error. Read more
source§

fn read_u64_be(&mut self) -> Result<u64>

Reads a big-endian u64 returning it’s value or an Error. Read more
source§

fn read_i128_le(&mut self) -> Result<i128>

Reads a little-endian i128 returning it’s value or an Error. Read more
source§

fn read_u128_le(&mut self) -> Result<u128>

Reads a little-endian u128 returning it’s value or an Error. Read more
source§

fn read_i128_be(&mut self) -> Result<i128>

Reads a big-endian i128 returning it’s value or an Error. Read more
source§

fn read_u128_be(&mut self) -> Result<u128>

Reads a big-endian u128 returning it’s value or an Error. Read more
source§

impl<T: AsRef<[u8]>> ReadVarint for Cursor<T>

source§

fn read_varint(&mut self) -> Result<u64>

Read an unsigned varint from the stream. Read more
source§

fn read_signed_varint(&mut self) -> Result<i64>

Read a signed varint from the stream. Read more
source§

impl<T: AsRef<[u8]>> Seek for Cursor<T>

source§

fn seek(&mut self, pos: SeekFrom) -> Result<u64>

Adjust the current position of the stream. Read more
source§

fn rewind(&mut self) -> Result<()>

Set the current position of the stream to its beginning. Read more
source§

fn stream_len(&mut self) -> Result<u64>

Returns the length of the stream. Read more
source§

fn stream_position(&mut self) -> Result<u64>

Returns the current position of the stream. Read more
source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> Write for Cursor<T>

source§

fn write(&mut self, buf: &[u8]) -> Result<usize>

Write a buffer to a stream. Read more
source§

fn flush(&mut self) -> Result<()>

Commit any outstanding buffered writes to underlying storage. Read more
source§

fn write_all(&mut self, buf: &[u8]) -> Result<()>

Writes entire buffer to stream. Read more
source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> WriteInteger for Cursor<T>

source§

fn write_i8_le(&mut self, value: &i8) -> Result<()>

Writes a little-endian i8. Read more
source§

fn write_u8_le(&mut self, value: &u8) -> Result<()>

Writes a little-endian u8. Read more
source§

fn write_i8_be(&mut self, value: &i8) -> Result<()>

Writes a big-endian i8. Read more
source§

fn write_u8_be(&mut self, value: &u8) -> Result<()>

Writes a big-endian u8. Read more
source§

fn write_i16_le(&mut self, value: &i16) -> Result<()>

Writes a little-endian i16. Read more
source§

fn write_u16_le(&mut self, value: &u16) -> Result<()>

Writes a little-endian u16. Read more
source§

fn write_i16_be(&mut self, value: &i16) -> Result<()>

Writes a big-endian i16. Read more
source§

fn write_u16_be(&mut self, value: &u16) -> Result<()>

Writes a big-endian u16. Read more
source§

fn write_i32_le(&mut self, value: &i32) -> Result<()>

Writes a little-endian i32. Read more
source§

fn write_u32_le(&mut self, value: &u32) -> Result<()>

Writes a little-endian u32. Read more
source§

fn write_i32_be(&mut self, value: &i32) -> Result<()>

Writes a big-endian i32. Read more
source§

fn write_u32_be(&mut self, value: &u32) -> Result<()>

Writes a big-endian u32. Read more
source§

fn write_i64_le(&mut self, value: &i64) -> Result<()>

Writes a little-endian i64. Read more
source§

fn write_u64_le(&mut self, value: &u64) -> Result<()>

Writes a little-endian u64. Read more
source§

fn write_i64_be(&mut self, value: &i64) -> Result<()>

Writes a big-endian i64. Read more
source§

fn write_u64_be(&mut self, value: &u64) -> Result<()>

Writes a big-endian u64. Read more
source§

fn write_i128_le(&mut self, value: &i128) -> Result<()>

Writes a little-endian i128. Read more
source§

fn write_u128_le(&mut self, value: &u128) -> Result<()>

Writes a little-endian u128. Read more
source§

fn write_i128_be(&mut self, value: &i128) -> Result<()>

Writes a big-endian i128. Read more
source§

fn write_u128_be(&mut self, value: &u128) -> Result<()>

Writes a big-endian u128. Read more
source§

impl<T: AsRef<[u8]> + AsMut<[u8]>> WriteVarint for Cursor<T>

source§

fn write_varint(&mut self, value: u64) -> Result<()>

Write an unsigned varint to the stream. Read more
source§

fn write_signed_varint(&mut self, value: i64) -> Result<()>

Write a signed varint to 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<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.