pub trait WriteAllExt: Write {
// Provided methods
fn write_bool(&mut self, boolean: bool) -> Result<()> { ... }
fn write_num_be<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
where N: ToBytes<Bytes = [u8; SIZE]> { ... }
fn write_num_le<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
where N: ToBytes<Bytes = [u8; SIZE]> { ... }
fn write_num_ne<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
where N: ToBytes<Bytes = [u8; SIZE]> { ... }
}Provided Methods§
Sourcefn write_bool(&mut self, boolean: bool) -> Result<()>
fn write_bool(&mut self, boolean: bool) -> Result<()>
Write a bool as one byte.
For further semantics please refer to Read::read_exact.
§Examples
use rw_exact_ext::WriteAllExt;
use std::io::Cursor;
let mut bytes = vec![0xFF];
Cursor::new(&mut bytes).write_bool(true).unwrap();
assert_eq!(bytes, [0x01]);
Cursor::new(&mut bytes).write_bool(false).unwrap();
assert_eq!(bytes, [0x00]);Sourcefn write_num_be<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
fn write_num_be<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
Write a number to bytes in big endian.
For further semantics please refer to Write::write_all.
§Examples
use rw_exact_ext::WriteAllExt;
use std::io::Cursor;
let mut bytes = vec![0u8; 4];
let unsigned: u32 = 1337;
Cursor::new(&mut bytes).write_num_be(unsigned).unwrap();
assert_eq!(bytes, vec![0x00, 0x00, 0x05, 0x39]);
let signed: i32 = -1337;
Cursor::new(&mut bytes).write_num_be(signed).unwrap();
assert_eq!(bytes, vec![0xFF, 0xFF, 0xFA, 0xC7]);
let float: f32 = 133.7;
Cursor::new(&mut bytes).write_num_be(float).unwrap();
assert_eq!(bytes, vec![0x43, 0x05, 0xB3, 0x33]);Sourcefn write_num_le<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
fn write_num_le<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
Write a number to bytes in little endian.
For further semantics please refer to Write::write_all.
§Examples
use rw_exact_ext::WriteAllExt;
use std::io::Cursor;
let mut bytes = vec![0u8; 4];
let unsigned: u32 = 1337;
Cursor::new(&mut bytes).write_num_le(unsigned).unwrap();
assert_eq!(bytes, vec![0x39, 0x05, 0x00, 0x00]);
let signed: i32 = -1337;
Cursor::new(&mut bytes).write_num_le(signed).unwrap();
assert_eq!(bytes, vec![0xC7, 0xFA, 0xFF, 0xFF]);
let float: f32 = 133.7;
Cursor::new(&mut bytes).write_num_le(float).unwrap();
assert_eq!(bytes, vec![0x33, 0xB3, 0x05, 0x43]);Sourcefn write_num_ne<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
fn write_num_ne<N, const SIZE: usize>(&mut self, num: N) -> Result<()>
Write a number to bytes in native endianness.
For further semantics please refer to Write::write_all.
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.