mirror of
https://github.com/rust-lang/rustlings.git
synced 2026-01-10 12:49:18 +00:00
Fix: Convert Sun to the unit struct
This commit is contained in:
parent
30291a3c25
commit
a42efe9182
@ -10,7 +10,7 @@
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Debug)]
|
||||
struct Sun {}
|
||||
struct Sun;
|
||||
|
||||
#[derive(Debug)]
|
||||
enum Planet {
|
||||
@ -31,7 +31,7 @@ impl Planet {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let sun = Rc::new(Sun {});
|
||||
let sun = Rc::new(Sun);
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 1 reference
|
||||
|
||||
let mercury = Planet::Mercury(Rc::clone(&sun));
|
||||
@ -55,17 +55,17 @@ fn main() {
|
||||
jupiter.details();
|
||||
|
||||
// TODO
|
||||
let saturn = Planet::Saturn(Rc::new(Sun {}));
|
||||
let saturn = Planet::Saturn(Rc::new(Sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 7 references
|
||||
saturn.details();
|
||||
|
||||
// TODO
|
||||
let uranus = Planet::Uranus(Rc::new(Sun {}));
|
||||
let uranus = Planet::Uranus(Rc::new(Sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 8 references
|
||||
uranus.details();
|
||||
|
||||
// TODO
|
||||
let neptune = Planet::Neptune(Rc::new(Sun {}));
|
||||
let neptune = Planet::Neptune(Rc::new(Sun));
|
||||
println!("reference count = {}", Rc::strong_count(&sun)); // 9 references
|
||||
neptune.details();
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user