The example below is just an example, I know I don't need the Clone for this to work, but if S were an enum with [T] and Vec<T> and I wanted to resize the vector, T would have to be Clone.
struct S<'a, T>{
a: &'a [T]
}
impl<'a, T> S<'a, T> {
pub fn borrow(&self) -> &[T]
where [T]: Clone {
self.a
}
}
fn main() {
let slice:[u8;3] = [1,2,3];
let x = S{a: &slice};
x.borrow();
}
Error:
error[E0277]: the trait bound `[u8]: Clone` is not satisfied
--> src/main.rs:17:7
|
17 | x.borrow();
| ^^^^^^ the trait `Clone` is not implemented for `[u8]`
So, why isn't [u8] Clone?