I defined below structs:
#[derive(Debug, Copy, Clone)]
pub struct Truck<'a> {
socket: Sender,
unique_id: &'a str
}
#[derive(Debug, Copy, Clone)]
pub struct Clients<'a> {
pub client: Vec<&'a Truck<'a>>
}
impl Clients {
pub fn new() -> Self { Clients { client: Vec::new() } }
pub fn insert(&mut self, t: Truck) {
self.client.push(t.borrow())
}
}
static mut clients:Clients = Clients::new();
But while compiling, got the below errors:
error[E0204]: the trait `Copy` may not be implemented for this type
--> src/socket.rs:26:17
|
26 | #[derive(Debug, Copy, Clone)]
| ^^^^
27 | pub struct Truck<'a> {
28 | socket: Sender,
| -------------- this field does not implement `Copy`
error[E0204]: the trait `Copy` may not be implemented for this type
--> src/socket.rs:37:17
|
37 | #[derive(Debug, Copy, Clone)]
| ^^^^
38 | pub struct Clients<'a> {
39 | pub client: Vec<&'a Truck<'a>>
| ------------------------------ this field does not implement `Copy`
error: aborting due to 2 previous errors
Once I removed the #[derive(Copy)]
, I got this error:
error[E0507]: cannot move out of static item `clients`
--> src/socket.rs:56:18
|
56 | unsafe { clients }.insert(truck);
| ^^^^^^^ move occurs because `clients` has type `socket::Clients`, which does not implement the `Copy` trait