DataStream

Struct DataStream 

Source
pub struct DataStream<T> { /* private fields */ }
Expand description

A stream that allows endian-aware read and write.

This struct is generic over any type T that implements some combination of Read, Write, and Seek. Methods are conditionally available based on the traits implemented by T.

Implementations§

Source§

impl<T> DataStream<T>

Source

pub const fn new(inner: T, endian: Endian) -> Self

Creates a new DataStream with the given inner stream and endianness.

Trait Implementations§

Source§

impl<T: Debug> Debug for DataStream<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> Deref for DataStream<T>

Source§

type Target = T

The resulting type after dereferencing.
Source§

fn deref(&self) -> &Self::Target

Dereferences the value.
Source§

impl<T> DerefMut for DataStream<T>

Source§

fn deref_mut(&mut self) -> &mut Self::Target

Mutably dereferences the value.
Source§

impl<T> EndianExt for DataStream<T>

Source§

fn endian(&self) -> Endian

Returns the current endianness.
Source§

fn set_endian(&mut self, endian: Endian)

Sets the endianness.
Source§

impl<T: Read> ReadExt for DataStream<T>

Source§

fn read_exact<const N: usize>(&mut self) -> Result<[u8; N], DataError>

Reads exactly N bytes from the current stream. Read more
Source§

fn read_length(&mut self, buffer: &mut [u8]) -> Result<usize, DataError>

Attempts to fill the buffer with data. Read more
Source§

fn read_slice(&mut self, length: usize) -> Result<Cow<'_, [u8]>, DataError>

Reads a slice of the given length from the current position. Read more
Source§

fn remaining_slice(&mut self) -> Result<Cow<'_, [u8]>, DataError>

Returns the remaining data from the current position. Read more
Source§

fn read_string(&mut self, length: usize) -> Result<Cow<'_, str>, DataError>

Reads a UTF-8 encoded string of the given length from the current position. Read more
Source§

fn read_u8(&mut self) -> Result<u8, DataError>

Reads an unsigned 8-bit integer. Read more
Source§

fn read_i8(&mut self) -> Result<i8, DataError>

Reads a signed 8-bit integer. Read more
Source§

fn read_u16(&mut self) -> Result<u16, DataError>

Reads an unsigned 16-bit integer. Read more
Source§

fn read_i16(&mut self) -> Result<i16, DataError>

Reads a signed 16-bit integer. Read more
Source§

fn read_u32(&mut self) -> Result<u32, DataError>

Reads an unsigned 32-bit integer. Read more
Source§

fn read_i32(&mut self) -> Result<i32, DataError>

Reads a signed 32-bit integer. Read more
Source§

fn read_u64(&mut self) -> Result<u64, DataError>

Reads an unsigned 64-bit integer. Read more
Source§

fn read_i64(&mut self) -> Result<i64, DataError>

Reads a signed 64-bit integer. Read more
Source§

fn read_f32(&mut self) -> Result<f32, DataError>

Reads a 32-bit floating point number. Read more
Source§

fn read_f64(&mut self) -> Result<f64, DataError>

Reads a 64-bit floating point number. Read more
Source§

impl<T: Seek> SeekExt for DataStream<T>

Source§

fn len(&mut self) -> Result<u64, DataError>

Returns the total length of the data.

Note that this can be an expensive operation due to seeking. You should instead use something like std::fs::Metadata::len.

§Errors

Returns an error if unable to determine the length of the stream.

Source§

fn is_empty(&mut self) -> Result<bool, DataError>

Returns true if the remaining data is empty.

Note that this can be an expensive operation due to seeking.

§Errors

Returns an error if unable to determine either the length of the stream or the position inside it.

Source§

fn position(&mut self) -> Result<u64, DataError>

Returns the current position.
Source§

fn set_position(&mut self, position: u64) -> Result<u64, DataError>

Sets the current position. Read more
Source§

impl<T: Write> WriteExt for DataStream<T>

Source§

fn write_exact<const N: usize>( &mut self, bytes: &[u8; N], ) -> Result<(), DataError>

Writes exactly N bytes to the current stream. Read more
Source§

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

Writes an unsigned 8-bit integer. Read more
Source§

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

Writes a signed 8-bit integer. Read more
Source§

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

Writes an unsigned 16-bit integer. Read more
Source§

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

Writes a signed 16-bit integer. Read more
Source§

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

Writes an unsigned 32-bit integer. Read more
Source§

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

Writes a signed 32-bit integer. Read more
Source§

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

Writes an unsigned 64-bit integer. Read more
Source§

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

Writes a signed 64-bit integer. Read more
Source§

fn write_f32(&mut self, value: f32) -> Result<(), DataError>

Writes a 32-bit floating point number. Read more
Source§

fn write_f64(&mut self, value: f64) -> Result<(), DataError>

Writes a 64-bit floating point number. Read more

Auto Trait Implementations§

§

impl<T> Freeze for DataStream<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for DataStream<T>
where T: RefUnwindSafe,

§

impl<T> Send for DataStream<T>
where T: Send,

§

impl<T> Sync for DataStream<T>
where T: Sync,

§

impl<T> Unpin for DataStream<T>
where T: Unpin,

§

impl<T> UnwindSafe for DataStream<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<P, T> Receiver for P
where P: Deref<Target = T> + ?Sized, T: ?Sized,

Source§

type Target = T

🔬This is a nightly-only experimental API. (arbitrary_self_types)
The target type on which the method may be called.
Source§

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

Source§

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>,

Source§

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.