|
@@ -5,8 +5,12 @@ pub use byteorder::{ReadBytesExt, WriteBytesExt};
|
|
|
pub type Reader<'a> = &'a [u8];
|
|
pub type Reader<'a> = &'a [u8];
|
|
|
pub type Writer = Vec<u8>;
|
|
pub type Writer = Vec<u8>;
|
|
|
|
|
|
|
|
|
|
+/// A type that can be serialized to and from bytes.
|
|
|
|
|
+/// Should only be implemented on types that own their data, i.e. `String` and not `&str`.
|
|
|
pub trait Io : Sized {
|
|
pub trait Io : Sized {
|
|
|
|
|
+ /// Read data from the reader.
|
|
|
fn read(r: &mut Reader) -> Result<Self>;
|
|
fn read(r: &mut Reader) -> Result<Self>;
|
|
|
|
|
|
|
|
|
|
+ /// Write this data to the reader.
|
|
|
fn write(&self, w: &mut Writer) -> Result<()>;
|
|
fn write(&self, w: &mut Writer) -> Result<()>;
|
|
|
}
|
|
}
|