Copy not implemented - trait inheritance


#1

I’m trying to define a trait in a class that needs to be copyable. This seems fine to me but the compiler is not happy. I can’t seem to find documentation or discussions on my issue - any help would be appreciated!

#[derive(Clone, Copy, Debug)]
pub struct Buffer {
    stream: Stream
}

pub trait Stream: Copy + Clone {
    fn next(&self) -> Stream;
}

error[E0204]: the trait Copy may not be implemented for this type
–> src/pieces/mod.rs:30:17
|
| #[derive(Clone, Copy, Debug)]
|                           ^^^^

| generator: TetrominoStream
| -------------------------- this field does not implement Copy

Thank you


#2
error[E0038]: the trait `Stream` cannot be made into an object

Seems the more appropriate error.

Maybe you are after;

#[derive(Clone, Copy, Debug)]
pub struct Buffer<S: Stream> {
    stream: S
}

#3

Ah thank you! Is this one of those situations where the compiler should be providing less cryptic error messages?