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

Obtains a new reader or writer that assumes data in little endian.

Obtains a new reader or writer that assumes data in big endian.

Obtains a new reader or writer that assumes data in the system’s native endianness. While this method might sounds a bit pointless, it enables easier byte order changes through method chaining).

Obtains a new reader or writer that assumes network order.

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.

Converts from ByteOrdered<T, E> to ByteOrdered<&mut T, E>, copying the endianness information.

Disbands a ByteOrder into its parts.

Maps a ByteOrdered<T, E> into a ByteOrdered<O, E> by applying the given function to the inner reader or writer.

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).

Changes the assumed byte order of the reader or writer to little endian.

Changes the assumed byte order of the reader or writer to little endian.

Changes the assumed byte order of the reader or writer to the system’s native endianness.

Converts the assumed endianness to the opposite of the current order.

Retrieves the byte order assumed by this wrapper.

Checks whether the assumed endianness is the system’s native byte order.

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.

Writes a IEEE754 double-precision (8 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

Returns an iterator over the lines of this reader. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

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

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Reader has an efficient read_vectored implementation. Read more

🔬 This is a nightly-only experimental API. (read_initializer)

Determines if this Reader can work with buffers of uninitialized memory. Read more

Creates a “by reference” adapter for this instance of Read. Read more

Transforms this Read instance to an Iterator over its bytes. Read more

Creates an adapter which will chain this stream with another. Read more

Creates an adapter which will read at most limit bytes from it. Read more

Seek to an offset, in bytes, in a stream. Read more

Rewind to the beginning of a stream. Read more

🔬 This is a nightly-only experimental API. (seek_stream_len)

Returns the length of this stream (in bytes). Read more

Returns the current seek position from the start of the stream. 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

Like write, except that it writes from a slice of buffers. Read more

🔬 This is a nightly-only experimental API. (can_vector)

Determines if this Writer has an efficient write_vectored implementation. Read more

🔬 This is a nightly-only experimental API. (write_all_vectored)

Attempts to write multiple buffers into this writer. Read more

Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

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

👎 Deprecated since 1.2.0:

please use read_f32_into instead

DEPRECATED. Read more

Reads a sequence of IEEE754 double-precision (8 bytes) floating point numbers from the underlying reader. Read more

👎 Deprecated since 1.2.0:

please use read_f64_into instead

DEPRECATED. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

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

Writes a IEEE754 double-precision (8 bytes) floating point number to the underlying writer. Read more