pub trait WriteBytesExt: Write {
Show 14 methods
// Provided methods
fn write_u8(&mut self, n: u8) -> Result<(), Error> { ... }
fn write_i8(&mut self, n: i8) -> Result<(), Error> { ... }
fn write_u16<T>(&mut self, n: u16) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_i16<T>(&mut self, n: i16) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_u24<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_i24<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_u32<T>(&mut self, n: u32) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_i32<T>(&mut self, n: i32) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_u64<T>(&mut self, n: u64) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_i64<T>(&mut self, n: i64) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_f32<T>(&mut self, n: f32) -> Result<(), Error>
where T: ByteOrder { ... }
fn write_f64<T>(&mut self, n: f64) -> Result<(), Error>
where T: ByteOrder { ... }
}
Expand description
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§
Sourcefn write_u8(&mut self, n: u8) -> Result<(), Error>
fn write_u8(&mut self, n: u8) -> Result<(), Error>
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
.
Sourcefn write_i8(&mut self, n: i8) -> Result<(), Error>
fn write_i8(&mut self, n: i8) -> Result<(), Error>
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
.
Sourcefn write_u16<T>(&mut self, n: u16) -> Result<(), Error>where
T: ByteOrder,
fn write_u16<T>(&mut self, n: u16) -> Result<(), Error>where
T: ByteOrder,
Writes an unsigned 16 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_i16<T>(&mut self, n: i16) -> Result<(), Error>where
T: ByteOrder,
fn write_i16<T>(&mut self, n: i16) -> Result<(), Error>where
T: ByteOrder,
Writes a signed 16 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_u24<T>(&mut self, n: u32) -> Result<(), Error>where
T: ByteOrder,
fn write_u24<T>(&mut self, n: u32) -> Result<(), Error>where
T: ByteOrder,
Writes an unsigned 24 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_i24<T>(&mut self, n: i32) -> Result<(), Error>where
T: ByteOrder,
fn write_i24<T>(&mut self, n: i32) -> Result<(), Error>where
T: ByteOrder,
Writes a signed 24 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_u32<T>(&mut self, n: u32) -> Result<(), Error>where
T: ByteOrder,
fn write_u32<T>(&mut self, n: u32) -> Result<(), Error>where
T: ByteOrder,
Writes an unsigned 32 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_i32<T>(&mut self, n: i32) -> Result<(), Error>where
T: ByteOrder,
fn write_i32<T>(&mut self, n: i32) -> Result<(), Error>where
T: ByteOrder,
Writes a signed 32 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_u64<T>(&mut self, n: u64) -> Result<(), Error>where
T: ByteOrder,
fn write_u64<T>(&mut self, n: u64) -> Result<(), Error>where
T: ByteOrder,
Writes an unsigned 64 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_i64<T>(&mut self, n: i64) -> Result<(), Error>where
T: ByteOrder,
fn write_i64<T>(&mut self, n: i64) -> Result<(), Error>where
T: ByteOrder,
Writes a signed 64 bit integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
Sourcefn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>where
T: ByteOrder,
fn write_uint<T>(&mut self, n: u64, nbytes: usize) -> Result<(), Error>where
T: ByteOrder,
Writes an unsigned n-bytes integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
§Panics
If the given integer is not representable in the given number of bytes,
this method panics. If nbytes > 8
, this method panics.
Sourcefn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>where
T: ByteOrder,
fn write_int<T>(&mut self, n: i64, nbytes: usize) -> Result<(), Error>where
T: ByteOrder,
Writes a signed n-bytes integer to the underlying writer.
§Errors
This method returns the same errors as Write::write_all
.
§Panics
If the given integer is not representable in the given number of bytes,
this method panics. If nbytes > 8
, this method panics.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
impl<W> WriteBytesExt for W
All types that implement Write
get methods defined in WriteBytesExt
for free.