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
43
use std::fmt;
use std::io::{Read, Result as IoResult};
use failure::Error;
pub use abi::Einittoken;
use abi::{Attributes, Sigstruct};
pub trait EinittokenProvider: fmt::Debug {
fn token(
&mut self,
sigstruct: &Sigstruct,
attributes: Attributes,
retry: bool,
) -> Result<Einittoken, Error>;
fn can_retry(&self) -> bool;
}
impl<P: EinittokenProvider + 'static> From<P> for Box<dyn EinittokenProvider> {
fn from(p: P) -> Self {
Box::new(p)
}
}
pub fn read<R: Read>(reader: &mut R) -> IoResult<Einittoken> {
let mut buf = [0u8; 304];
reader.read_exact(&mut buf)?;
Einittoken::try_copy_from(&buf).ok_or_else(|| unreachable!())
}