The following code is a small example of a TryFrom
implementation for some structs A
and B
, with C
being used as the associated error type.
struct A;
struct B;
struct C;
impl TryFrom<A> for B {
type Error = C;
fn try_from(value: A) -> Result<Self, Self::Error> {
if some_condition() {
Ok(Self)
} else {
Err(Self::Error) // compiler Error
// Err(C) would work
}
}
}
Why can both Self
and Self::Error
be used in the return type of try_from
, but only Self
can be used to actually construct the return type?
Thanks for your assistance!