1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
extern crate twizzler_abi;

use std::marker::PhantomData;

pub mod collections;
pub mod io;
pub mod primitive;

pub use io::{Read, Seek, Write, IO};
pub use layout_derive::layout;

pub trait ApplyLayout<'a, R: IO>: Encode + Decode {
    type Frame: Frame<R> + 'a;

    fn apply_layout(stream: &'a mut R, offset: u64) -> Result<Self::Frame, R::Error>;
}

pub trait Frame<S> {
    fn stream(&mut self) -> &mut S;
    fn offset(&self) -> u64;
}

pub trait Decode: Sized {
    fn decode<R: Read + Seek + IO>(reader: &mut R) -> Result<Self, R::Error>;
}

pub trait Encode {
    fn encode<W: Write + Seek + IO>(&self, writer: &mut W) -> Result<(), W::Error>;
}

pub trait Fixed {
    fn size() -> u64;
}

pub trait FramedDynamic<R: IO> {
    fn framed_size(&mut self) -> Result<u64, R::Error>;
}

pub trait SourcedDynamic {
    fn sourced_size(&self) -> u64;
}