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