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
42
#![allow(warnings)]
#![cfg_attr(feature = "nightly", feature(array_try_map))]
#![doc = include_str!("../README.md")]
mod record;
mod types;
use core::convert::TryInto;
pub use data_view;
pub use data_view::DataView;
pub use derive::*;
pub use record::Record;
pub type Result<T> = core::result::Result<T, ErrorKind>;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ErrorKind {
InvalidType,
InvalidData,
InvalidInput,
InvalidLength,
Unsupported,
InsufficientBytes,
Other,
}
macro_rules! map {
[@err $item:expr ; $err_ty:tt] => { match $item { Ok(v) => v, _ => return Err(ErrorKind::$err_ty) } };
[@opt $item:expr ; $err_ty:tt] => { match $item { Some(v) => v, _ => return Err(ErrorKind::$err_ty) } };
}
pub(crate) use map;
pub trait DataType: Sized {
fn serialize(self, view: &mut DataView<impl AsMut<[u8]>>);
fn deserialize(view: &mut DataView<impl AsRef<[u8]>>) -> Result<Self>;
}