Macro format_bytes::write_bytes [−][src]
macro_rules! write_bytes {
($($args : tt) *) => { ... };
}
Expand description
Like format_bytes!
, but writes to a stream given as an additional first argument.
The stream is an expression of any type that implements the DisplayBytes
trait.
The macro returns std::io::Result<()>
.
Examples
use format_bytes::write_bytes;
const BUFFER_LEN: usize = 20;
let mut buffer = [0_u8; BUFFER_LEN];
let mut slice = &mut buffer[..];
write_bytes!(&mut slice, b"{}", 3.14).unwrap();
// `impl std::io::Write for &mut [u8]` reassigns the slice to the unwritten remainder:
let written = BUFFER_LEN - slice.len();
assert_eq!(&buffer[..written], b"3.14");