I'm trying to write the following code:
pub enum Error<T> {
Generic,
Transport(T),
}
impl<T: Transport> Device<T> {
pub fn new(t: T) -> Self {
Self(t)
}
pub fn thing(&mut self) -> Result<(), Error<T::Error>> {
self.0.transact(&[1, 2, 3], &mut [1, 2, 3])?; // <------------
Ok(())
}
}
pub trait Transport {
type Error;
fn transact(&mut self, command: &[u8], response: &mut [u8]) -> Result<(), Self::Error>;
}
But I'm unsure what my std::convert::From
signature should look like to allow me to convert from T::Error
to Error<T::Error>
at the arrowed line above.
Should I be trying to implement std::convert::From
in a generic way? Should I be adding a constraint to type Error
inside Transport
that makes implementers bring their own From
?