Make users type method syntax themselves in structs3#2296
Make users type method syntax themselves in structs3#2296senekor wants to merge 1 commit intorust-lang:mainfrom
structs3#2296Conversation
7c15c95 to
5eb1cee
Compare
| fn get_fees(&self, cents_per_gram: u32) { | ||
| // TODO: Calculate the package's fees. | ||
| // TODO: Turn this function into a method on `Fireworks`. | ||
| fn start(fireworks: Fireworks) -> String { |
There was a problem hiding this comment.
Why take ownership here? I really like the concept of the exercise which lets users write their own methods. But we need to find a better story where moving actually makes sense, also type wise. The struct should contain some field that isn't Copy.
There was a problem hiding this comment.
Why take ownership here?
You can't start the fireworks twice, so it must be consumed.
The struct should contain some field that isn't
Copy.
Why? There is no #[derive(Copy)]. Are you concerned users will cheat themselves?
There was a problem hiding this comment.
Actually, I think it doesn't matter if users add #[derive(Clone, Copy)]. The test where Fireworks::start(f) accepts ownership will still fail. So it shouldn't be an issue either way.
0e91eed to
4fd2c89
Compare
4fd2c89 to
7c1d8eb
Compare
closes #2286