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
use std::io;

mod imp;
pub use btmgmt_packet_macros::{Pack, Unpack};

#[derive(Debug, thiserror::Error)]
pub enum Error {
    #[error("no data available.")]
    NoDataAvailable,

    #[error(transparent)]
    Io(#[from] io::Error),

    #[error("unexpected value {0}")]
    UnexpectedValue(String),
}

pub type Result<R> = std::result::Result<R, Error>;

pub trait Pack {
    fn pack<W>(&self, write: &mut W) -> Result<()>
    where
        W: io::Write;
}

pub trait Unpack: Sized {
    fn unpack<R>(read: &mut R) -> Result<Self>
    where
        R: io::Read;
}