1use std::io::{Read, Write};
2
3use super::*;
4
5pub trait ReadFrom: Sized {
7 fn read_from<R: Read>(r: &mut R) -> Result<Self>;
8}
9
10pub trait ReadAtom: Sized {
12 fn read_atom<R: Read>(header: &Header, r: &mut R) -> Result<Self>;
13}
14
15pub trait ReadUntil: Sized {
17 fn read_until<R: Read>(r: &mut R) -> Result<Self>;
18}
19
20pub trait WriteTo {
22 fn write_to<W: Write>(&self, w: &mut W) -> Result<()>;
23}
24
25impl<T: Encode> WriteTo for T {
26 fn write_to<W: Write>(&self, w: &mut W) -> Result<()> {
27 let mut buf = Vec::new();
29 self.encode(&mut buf)?;
30 Ok(w.write_all(&buf)?)
31 }
32}