Hi, I was thinking... is there any use to set a trait condition on a struct or out of a function/impl block?
As example:
struct P<T> {
x: T,
}
impl<T: Clone> P<T> {
fn clone2(&self) -> Self {
P { x: self.x.clone() }
}
}
Any function we create, that could need a trait condition like the clone2 function, is enough to set the condition on the impl block, actually even put a condition on the struct definition, does not means the T on the impl block will inherit the condition, you still need to write the same condition, just to write it explicitly, this will not works:
struct P<T: Clone> {
x: T,
}
impl<T> P<T> {
fn clone2(&self) -> Self {
P { x: self.x.clone() }
}
}
By the way I do not understand why in the impl black, P is not restricted to the struct definition, seems weird, still is on the side of the question.
Is there any useful case where the condition is used on the struct declaration and not in the impl block?
Also force a trait on the struct, would force use to use that condition on the impl block too, but seems not useful at all, because without it, we still would get an error to declare in the impl T with Clone.
Thx!