Created
October 27, 2019 13:42
-
-
Save rust-play/d1a94cea570e927b9dabedfd2069470a to your computer and use it in GitHub Desktop.
Code shared from the Rust Playground
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::rc::Rc; | |
#[derive(Debug)] | |
struct Foo { | |
bar: usize, | |
} | |
impl Foo { | |
fn rc(bar: usize) -> Rc<Self> { | |
Rc::new(Foo { bar }) | |
} | |
} | |
fn main(){ | |
let mut a = vec![Foo::rc(1), Foo::rc(2), Foo::rc(3)]; | |
let b = vec![Foo::rc(4), Foo::rc(5)]; | |
println!("Before:"); | |
println!("{:?}", a); | |
println!("{:?}\n", b); | |
a.append(&mut b.clone()); | |
println!("After:"); | |
println!("{:?}", a); | |
println!("{:?}\n", b); | |
println!("Strong references to b[0] / a[3]: {}", Rc::strong_count(&b[0])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment