use std::rc::Rc;
struct A {
a: Rc<Vec<u8>>,
b: B
}
impl A {
fn new() -> Self {
let a = Rc::new(vec![1,2,3]);
Self {
a,
b: B::new(a.clone())
}
}
}
struct B {
a: Rc<Vec<u8>>
}
impl B {
fn new(a: Rc<Vec<u8>>) -> Self {
Self {
a
}
}
}
/* This would work
impl A {
fn new() -> Self {
let a = Rc::new(vec![1,2,3]);
let b = a.clone();
Self {
a,
b: B::new(b)
}
}
}
*/
fn main() {
let _a = A::new();
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0382]: borrow of moved value: `a`
--> src/main.rs:13:23
|
10 | let a = Rc::new(vec![1,2,3]);
| - move occurs because `a` has type `std::rc::Rc<std::vec::Vec<u8>>`, which does not implement the `Copy` trait
11 | Self {
12 | a,
| - value moved here
13 | b: B::new(a.clone())
| ^ value borrowed here after move
error: aborting due to previous error
For more information about this error, try `rustc --explain E0382`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.