I have this code (in playground):
trait Limit {}
pub trait Trait
{
fn give<T>(&self, x: T) -> T
where T: Limit;
}
struct Struct<T: Limit> {field: T}
impl<T> Trait for Struct<T>
where T: Limit
{
fn give<S>(&self, x: S) -> S
where S: Limit
{
self.field
//interacts with x parameter and gives an "S: Limit" result
}
}
What I want to do is to keep the signature of give
function of the trait Trait
and at the same time to implement the trait Trait
for a the generic struct Struct
.
but I get this error
<anon>:17:8: 17:14 error: mismatched types:
expected `S`,
found `T`
(expected type parameter,
found a different type parameter) [E0308]
<anon>:17 self.field
^~~~~~
I thought to use what I saw in this question which matches an associated parameter with a generic parameter so I changed:
fn give<S>(&self, x: S) -> S
where S: Limit
to:
fn give<S = T>(&self, x: S) -> S
where S: Limit
I didn't get an error about this syntax but it wasn't the solution of the error above.
Is there any way to achieve what I want to do?
And a side question, what <S = T>
actually does in this case?