Trait byteorder::WriteBytesExt [] [src]

pub trait WriteBytesExt: Write {
    fn write_u8(&mut self, n: u8) -> Result<()> { ... }
    fn write_i8(&mut self, n: i8) -> Result<()> { ... }
    fn write_u16<T: ByteOrder>(&mut self, n: u16) -> Result<()> { ... }
    fn write_i16<T: ByteOrder>(&mut self, n: i16) -> Result<()> { ... }
    fn write_u32<T: ByteOrder>(&mut self, n: u32) -> Result<()> { ... }
    fn write_i32<T: ByteOrder>(&mut self, n: i32) -> Result<()> { ... }
    fn write_u64<T: ByteOrder>(&mut self, n: u64) -> Result<()> { ... }
    fn write_i64<T: ByteOrder>(&mut self, n: i64) -> Result<()> { ... }
    fn write_f32<T: ByteOrder>(&mut self, n: f32) -> Result<()> { ... }
    fn write_f64<T: ByteOrder>(&mut self, n: f64) -> Result<()> { ... }
}

Extends Write with methods for writing numbers. (For std::io.)

Most of the methods defined here have an unconstrained type parameter that must be explicitly instantiated. Typically, it is instantiated with either the BigEndian or LittleEndian types defined in this crate.

Examples

Write unsigned 16 bit big-endian integers to a Write:

use byteorder::{BigEndian, WriteBytesExt};

let mut wtr = vec![];
wtr.write_u16::<BigEndian>(517).unwrap();
wtr.write_u16::<BigEndian>(768).unwrap();
assert_eq!(wtr, vec![2, 5, 3, 0]);

Provided Methods

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

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.

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

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.

fn write_u16<T: ByteOrder>(&mut self, n: u16) -> Result<()>

Writes an unsigned 16 bit integer to the underlying writer.

fn write_i16<T: ByteOrder>(&mut self, n: i16) -> Result<()>

Writes a signed 16 bit integer to the underlying writer.

fn write_u32<T: ByteOrder>(&mut self, n: u32) -> Result<()>

Writes an unsigned 32 bit integer to the underlying writer.

fn write_i32<T: ByteOrder>(&mut self, n: i32) -> Result<()>

Writes a signed 32 bit integer to the underlying writer.

fn write_u64<T: ByteOrder>(&mut self, n: u64) -> Result<()>

Writes an unsigned 64 bit integer to the underlying writer.

fn write_i64<T: ByteOrder>(&mut self, n: i64) -> Result<()>

Writes a signed 64 bit integer to the underlying writer.

fn write_f32<T: ByteOrder>(&mut self, n: f32) -> Result<()>

Writes a IEEE754 single-precision (4 bytes) floating point number to the underlying writer.

fn write_f64<T: ByteOrder>(&mut self, n: f64) -> Result<()>

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

Implementors