3

If I have a parametric type like this:

struct Outer<A> {
   inner: A,
}

Is it possible to create an implementation of the From trait for Outer that will convert Outer<A> to Outer<B> if there exists a From that converts A to B?

Something like this (which doesn't work, as far as I can tell):

impl<A, B: From<A>> From<Outer<A>> for Outer<B> {
    fn from(oa: Outer<A>) -> Self {
        Outer {
            inner: oa.inner.into(),
        }
    }
}
egerhard
  • 1,089
  • 1
  • 9
  • 18

0 Answers0