use alloc::boxed::Box;
use crate::instruction::{info, Instruction};
use super::error::MaybeMissError;
use super::Binary;
#[derive(Copy, Clone, Debug)]
pub struct BoxedError<B> {
inner: B,
}
impl<B> BoxedError<B> {
pub fn new(inner: B) -> Self {
Self { inner }
}
}
impl<B> From<B> for BoxedError<B> {
fn from(inner: B) -> Self {
Self { inner }
}
}
impl<B, I> Binary<I> for BoxedError<B>
where
B: Binary<I>,
B::Error: MaybeMissError + 'static,
I: info::Info,
{
type Error = Box<dyn MaybeMissError>;
fn get_insn(&mut self, address: u64) -> Result<Instruction<I>, Self::Error> {
self.inner
.get_insn(address)
.map_err(|e| -> Box<dyn MaybeMissError> { Box::new(e) })
}
}