MCPcopy Create free account
hub / github.com/CleanCut/ultimate_rust2 / main

Function main

exercise/traits/src/main.rs:13–89  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

11}
12
13fn main() {
14 // 1. The code below doesn't work because Cake doesn't implement Debug.
15 // - Derive the Debug trait for the Cake enum above so this code will work. Then, run the code.
16
17 let cake = Cake::Spice;
18 admire_cake(cake);
19
20 // 2. Uncomment the code below. It doesn't work since `cake` was *moved* into the admire_cake()
21 // function. Let's fix the Cake enum so the code below works without any changes.
22 // - Derive the Copy trait for the Cake enum so that `cake` gets copied into the admire_cake()
23 // function instead of moved.
24 // - Hint: You may need to derive another trait in order to be able to derive the Copy trait
25
26 // match cake {
27 // Cake::Chocolate => println!("The name's Chocolate. Dark...Chocolate."),
28 // Cake::MapleBacon => println!("Dreams do come true!"),
29 // Cake::Spice => println!("Great, let's spice it up!"),
30 // }
31
32 // 3. Uncomment the println below. It doesn't work since the Party struct doesn't implement the
33 // Debug or Default traits.
34 // - Derive the Debug trait for the Party struct
35 // - Manually implement the Default trait for the Party struct. Use the value below as the
36 // default value that you return from the `default` method:
37 //
38 // Party {
39 // at_restaurant: true,
40 // num_people: 8,
41 // cake: Cake::Chocolate,
42 // }
43 //
44 // Hint: If you get stuck, there is an example at
45 // https://doc.rust-lang.org/std/default/trait.Default.html#how-can-i-implement-default
46
47 // println!("The default Party is\n{:#?}", Party::default());
48
49 // 4. You prefer Maple Bacon cake. Use "struct update syntax" to create a Party with `cake`
50 // set to `Cake::MapleBacon`, but the rest of the values are default.
51 //
52 // Hint: The trick to struct update syntax is specifying the value(s) you want to customize
53 // first and then ending the struct with `..Default::default()` -- but no comma after that!
54
55 // let party = Party {
56 // ...
57 // };
58 // println!("Yes! My party has my favorite {:?} cake!", party.cake);
59
60 // 5. Parties are "equal" if they have the same cake.
61 // - Derive the PartialEq trait for the Cake enum so Cakes can be compared.
62 // - Manually implement the PartialEq trait for Party. If different parties have the same cake,
63 // then they are equal, no matter the location or number of attendees at the party.
64 // - Uncomment and run the code below.
65
66 // let other_party = Party {
67 // at_restaurant: false,
68 // num_people: 235,
69 // cake: Cake::MapleBacon,
70 // };

Callers

nothing calls this directly

Calls 1

admire_cakeFunction · 0.85

Tested by

no test coverage detected