I have a trait
pub trait FromContext {
fn from_context<T>(context: Context<T>) -> Result<Self>;
}
and I would like to have an implementation of that trait like this
pub struct State<T>(pub T);
impl<T> FromContext for State<T> {
fn from_context<T>(context: Context<T>) -> Result<Self> {
Result::Ok(State(context.state))
}
}
but I get the error
error[E0403]: the name `T` is already used for a generic parameter in this item's generic parameters
I also tried
impl<T1> FromContext for State<T1> {
fn from_context<T2>(context: Context<T2>) -> Result<Self> {
Result::Ok(State(context.state))
}
}
but then I get
error[E0308]: mismatched types
Is there anyway to tell Rust T1
and T2
should be equal?
1