Struct byteordered::ByteOrdered [−][src]
pub struct ByteOrdered<T, E> { /* fields omitted */ }
Expand description
Wrapper type for a reader or writer with an assumed byte order.
More details can be found at the crate level documentation.
Implementations
Creates a new reader or writer that assumes data in the given byte
order known at run-time.
That is, the type representing the byte order
is the enum type Endianness
.
Although it is equivalent to ByteOrdered::new
, this function
leaves a code signal that subsequent calls depend on conditions
resolved at run-time. If you know the data’s endianness in compile
time, the other constructors are preferred (e.g. new
, le
or
be
), so as to avoid the overhead of dynamic dispatching.
Creates a new reader or writer that assumes data in the given byte order. This flexible constructor admits any kind of byte order (static and dynamic).
Note: The other constructors (le
, be
, native
, and
runtime
) are more recommended because they are easier to use and
leave a better signal of whether the endianness is known at compile
time or at run time. For example, if you pass a value literal of type
Endianness
(such as Endianness::Little
), the program will perform
dynamic dispatching in spite of the fixed byte order. The use of this
method is more appropriate when constructing functions which are
generic over the endianness type.
Recovers the inner reader or writer from this wrapper. Information about the assumed byte order is discarded.
Obtains an exclusive mutable reference to the inner reader or writer in this wrapper. Information about the assumed byte order is ignored until the reference is dropped.
pub fn as_mut(&mut self) -> ByteOrdered<&mut T, E>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
where
E: Copy,
pub fn as_mut(&mut self) -> ByteOrdered<&mut T, E>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
where
E: Copy,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Converts from ByteOrdered<T, E>
to ByteOrdered<&mut T, E>
,
copying the endianness information.
Disbands a ByteOrder
into its parts.
pub fn map<F, U>(self, f: F) -> ByteOrdered<U, E>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
where
F: FnOnce(T) -> U,
pub fn map<F, U>(self, f: F) -> ByteOrdered<U, E>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
where
F: FnOnce(T) -> U,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Maps a ByteOrdered<T, E>
into a ByteOrdered<O, E>
by applying the
given function to the inner reader or writer.
pub fn into_endianness<E2: Endian>(self, endianness: E2) -> ByteOrdered<T, E2>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
pub fn into_endianness<E2: Endian>(self, endianness: E2) -> ByteOrdered<T, E2>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Changes the assumed byte order of the reader or writer.
Modifies the assumed byte order of the reader or writer
inline with the value.
Since the endianness type needs to be the same,
this function is only relevant when
E
is a run-time defined byte order
(see Endianness
).
pub fn into_le(self) -> ByteOrdered<T, StaticEndianness<LittleEndian>>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
pub fn into_le(self) -> ByteOrdered<T, StaticEndianness<LittleEndian>>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Changes the assumed byte order of the reader or writer to little endian.
pub fn into_be(self) -> ByteOrdered<T, StaticEndianness<BigEndian>>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
pub fn into_be(self) -> ByteOrdered<T, StaticEndianness<BigEndian>>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Changes the assumed byte order of the reader or writer to little endian.
pub fn into_native(self) -> ByteOrdered<T, StaticEndianness<NativeEndian>>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
pub fn into_native(self) -> ByteOrdered<T, StaticEndianness<NativeEndian>>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Changes the assumed byte order of the reader or writer to the system’s native endianness.
pub fn into_opposite(self) -> ByteOrdered<T, E::Opposite>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
where
E: Endian,
pub fn into_opposite(self) -> ByteOrdered<T, E::Opposite>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
where
E: Endian,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Converts the assumed endianness to the opposite of the current order.
Retrieves the byte order assumed by this wrapper.
Reads a signed 8 bit integer from the underlying reader.
This method does exactly the same thing as read_i8
in
byteorder::ReadBytesExt
. It is included so that users do not have to
import the former trait.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 8 bit integers from a Read
:
use byteordered::ByteOrdered; let mut rdr = ByteOrdered::native(&[2, 5][..]); assert_eq!(2, rdr.read_i8()?); assert_eq!(5, rdr.read_i8()?);
Reads an unsigned 8 bit integer from the underlying reader.
This method does exactly the same thing as read_u8
in
byteorder::ReadBytesExt
. It is included so that users do not have to
import the former trait.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read unsigned 8 bit integers from a Read
:
use byteordered::ByteOrdered; let mut rdr = ByteOrdered::native(&[2, 5][..]); assert_eq!(2, rdr.read_u8()?); assert_eq!(5, rdr.read_u8()?);
Reads a signed 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read signed 16 bit big-endian integers from a Read
:
use byteordered::ByteOrdered; let mut rdr = ByteOrdered::be(&[0x00, 0xc1, 0xff, 0x7c][..]); assert_eq!(193, rdr.read_i16()?); assert_eq!(-132, rdr.read_i16()?);
Reads a sequence of signed 16 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Examples
Read two signed 16 bit big-endian integers from a Read
:
let mut out = [0; 2]; let mut rdr = ByteOrdered::be(&[0x00, 0xc1, 0xff, 0x7c][..]); rdr.read_i16_into(&mut out)?; assert_eq!(out, [193, -132]);
Reads an unsigned 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of unsigned 16 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads a signed 32 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of signed 32 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads an unsigned 32 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of unsigned 32 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads a signed 64 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of signed 64 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads an unsigned 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of unsigned 64 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads a signed 128 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of signed 128 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads an unsigned 16 bit integer from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of unsigned 128 bit integers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader.
Errors
This method returns the same errors as Read::read_exact
.
Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader.
The given buffer is either filled completely or an error is returned.
If an error is returned,
the contents of dst
are unspecified.
Errors
This method returns the same errors as Read::read_exact
.
Writes a signed 8 bit integer to the underlying writer.
Note that since this writes a single byte, no byte order conversions are used. It is included for completeness.
Errors
This method returns the same errors as Write::write_all
.
Writes an unsigned 8 bit integer to the underlying writer.
Note that since this writes a single byte, no byte order conversions are used. It is included for completeness.
Errors
This method returns the same errors as Write::write_all
.
Writes a signed 16 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Examples
Write signed 16 bit big-endian integers to a Write
:
use byteordered::ByteOrdered; let mut wtr = ByteOrdered::be(Vec::new()); wtr.write_i16(193).unwrap(); wtr.write_i16(-132).unwrap(); assert_eq!(wtr.into_inner(), b"\x00\xc1\xff\x7c");
Writes an unsigned 16 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes a signed 32 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes an unsigned 32 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes a signed 64 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes an unsigned 64 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes a signed 128 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes an unsigned 128 bit integer to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer.
Errors
This method returns the same errors as Write::write_all
.
Trait Implementations
Returns the contents of the internal buffer, filling it with more data from the inner reader if it is empty. Read more
Tells this buffer that amt
bytes have been consumed from the buffer,
so they should no longer be returned in calls to read
. Read more
Read all bytes into buf
until the delimiter byte
or EOF is reached. Read more
Read all bytes until a newline (the 0xA
byte) is reached, and append
them to the provided buffer. Read more
🔬 This is a nightly-only experimental API. (buf_read_has_data_left
)
recently added
Check if the underlying Read
has any data left to be read. Read more
Returns an iterator over the contents of this reader split on the byte
byte
. Read more
fn clone(&self) -> ByteOrdered<T, E>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
fn clone(&self) -> ByteOrdered<T, E>ⓘNotable traits for ByteOrdered<R, E>impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
impl<R, E> Read for ByteOrdered<R, E> where
R: Read, impl<W, E> Write for ByteOrdered<W, E> where
W: Write,
Returns a copy of the value. Read more
Performs copy-assignment from source
. Read more
Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Read all bytes until EOF in this source, placing them into buf
. Read more
Read all bytes until EOF in this source, appending them to buf
. Read more
Read the exact number of bytes required to fill buf
. Read more
Like read
, except that it reads into a slice of buffers. Read more
can_vector
)Determines if this Read
er has an efficient read_vectored
implementation. Read more
read_initializer
)Determines if this Read
er can work with buffers of uninitialized
memory. Read more
Creates a “by reference” adapter for this instance of Read
. Read more
Creates an adapter which will chain this stream with another. Read more
Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Attempts to write an entire buffer into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
can_vector
)Determines if this Write
r has an efficient write_vectored
implementation. Read more
write_all_vectored
)Attempts to write multiple buffers into this writer. Read more
Auto Trait Implementations
impl<T, E> RefUnwindSafe for ByteOrdered<T, E> where
E: RefUnwindSafe,
T: RefUnwindSafe,
impl<T, E> Send for ByteOrdered<T, E> where
E: Send,
T: Send,
impl<T, E> Sync for ByteOrdered<T, E> where
E: Sync,
T: Sync,
impl<T, E> Unpin for ByteOrdered<T, E> where
E: Unpin,
T: Unpin,
impl<T, E> UnwindSafe for ByteOrdered<T, E> where
E: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Reads an unsigned 8 bit integer from the underlying reader. Read more
Reads a signed 8 bit integer from the underlying reader. Read more
Reads an unsigned 16 bit integer from the underlying reader. Read more
Reads a signed 16 bit integer from the underlying reader. Read more
Reads an unsigned 24 bit integer from the underlying reader. Read more
Reads a signed 24 bit integer from the underlying reader. Read more
Reads an unsigned 32 bit integer from the underlying reader. Read more
Reads a signed 32 bit integer from the underlying reader. Read more
Reads an unsigned 48 bit integer from the underlying reader. Read more
Reads a signed 48 bit integer from the underlying reader. Read more
Reads an unsigned 64 bit integer from the underlying reader. Read more
Reads a signed 64 bit integer from the underlying reader. Read more
Reads an unsigned 128 bit integer from the underlying reader. Read more
Reads a signed 128 bit integer from the underlying reader. Read more
Reads an unsigned n-bytes integer from the underlying reader. Read more
Reads a signed n-bytes integer from the underlying reader. Read more
Reads an unsigned n-bytes integer from the underlying reader.
Reads a signed n-bytes integer from the underlying reader.
Reads a IEEE754 single-precision (4 bytes) floating point number from the underlying reader. Read more
Reads a IEEE754 double-precision (8 bytes) floating point number from the underlying reader. Read more
Reads a sequence of unsigned 16 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 32 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 64 bit integers from the underlying reader. Read more
Reads a sequence of unsigned 128 bit integers from the underlying reader. Read more
Reads a sequence of signed 8 bit integers from the underlying reader. Read more
Reads a sequence of signed 16 bit integers from the underlying reader. Read more
Reads a sequence of signed 32 bit integers from the underlying reader. Read more
Reads a sequence of signed 64 bit integers from the underlying reader. Read more
Reads a sequence of signed 128 bit integers from the underlying reader. Read more
Reads a sequence of IEEE754 single-precision (4 bytes) floating point numbers from the underlying reader. Read more
Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more
Writes an unsigned 8 bit integer to the underlying writer. Read more
Writes a signed 8 bit integer to the underlying writer. Read more
Writes an unsigned 16 bit integer to the underlying writer. Read more
Writes a signed 16 bit integer to the underlying writer. Read more
Writes an unsigned 24 bit integer to the underlying writer. Read more
Writes a signed 24 bit integer to the underlying writer. Read more
Writes an unsigned 32 bit integer to the underlying writer. Read more
Writes a signed 32 bit integer to the underlying writer. Read more
Writes an unsigned 48 bit integer to the underlying writer. Read more
Writes a signed 48 bit integer to the underlying writer. Read more
Writes an unsigned 64 bit integer to the underlying writer. Read more
Writes a signed 64 bit integer to the underlying writer. Read more
Writes an unsigned 128 bit integer to the underlying writer.
Writes a signed 128 bit integer to the underlying writer.
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes an unsigned n-bytes integer to the underlying writer. Read more
Writes a signed n-bytes integer to the underlying writer. Read more
Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer. Read more