use std::fmt;
use std::io::{Read, Result as IoResult};
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, anyhow::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!())
}