Expand description
Defines a trait built on top of io::Write
to write things into it.
use std::io;
trait WriteInto {
type Output;
fn write_into(self, sink: &mut impl io::Write) -> io::Result<Self::Output>;
}
The crate also provides wrappers, such as BigEndian
and LittleEndian
, to write values
in particular formats.
§Example
use write_into::{BigEndian, write_into};
let mut buffer = Vec::new();
write_into(&mut buffer, BigEndian(0xCAFEBABEu32)).unwrap();
assert_eq!(&buffer, &[0xCA, 0xFE, 0xBA, 0xBE]);
Structs§
- BigEndian
- Used to write values in big endian byte order.
- Little
Endian - Used to write values in little endian byte order.
- Plain
- Used to write values as they are represented in memory.
- Sequence
- Used to write values from
IntoIterator
. - Sized
- Used to write values prepended with size of their representation.
- Sized
Sequence - Used to write values from
IntoIterator
with known size. - Sleb128
- Used to write values in LEB-128 format (signed).
- Uleb128
- Used to write values in LEB-128 format (unsigned).
Traits§
- Write
Into - Writes value into I/O sink.
Functions§
- align_
position - Aligns position in the I/O sink to the given boundary and returns a new position.
- write_
into - An alias for
WriteInto::write_into
for writingwrite_into(sink, Wrapper(...))
instead ofWrapper(...).write_into(sink)
.