comprehensive-rust
comprehensive-rust copied to clipboard
Update match-expressions.md
The original code would always print "Unknown program name!".
Note that this allows multiple commands, and prints the message for each. So you can run:
cargo run rm mv
Hi @snoopdougiedougie, thanks for spotting this.
The original code would always print "Unknown program name!".
Yeah, I think I didn't pick a super good example to be honest. Perhaps we can rework it to something which lends itself better to an interactive class.
When teaching the class, I live code using the code on the slides (pages). Here it would be great to have a code snippet which both
- Is easy to modify in front of a class (
std::env::args()is not easy to modify in a playground environment 🙂) - Shows off the expression part. That is, I would like to assign the value of
matchto something.
Perhaps we can stay in the same theme and hard-code the arguments. We could then use match to determine the expected number of arguments... A problem with this is that all of these classical Unix programs take one or more arguments.
Perhaps we can find a better program name to match against — perhaps we say that we're reimplementing git instead and want to match its subcommands?
Yeah, it's hard to find a good example for a class. You want something "real-world", but not too difficult. The problem with parsing the command line to show how match works isn't how you usually accept command-line options in Rust--you usually use Clap.
works isn't how you usually accept command-line options in Rust--you usually use Clap.
True :smile: but I hope the students who take the class will forgive us for this. It would be cool to explain how to actually do it in a speaker note — I've just put up #107 which should help with that.
#107
wire
On Wed, Jan 4, 2023, 6:52 PM Martin Geisler @.***> wrote:
works isn't how you usually accept command-line options in Rust--you usually use Clap.
True 😄 but I hope the students who take the class will forgive us for this. It would be cool to explain how to actually do it in a speaker note — I've just put up #107 https://github.com/google/comprehensive-rust/pull/107 which should help with that.
— Reply to this email directly, view it on GitHub https://github.com/google/comprehensive-rust/pull/103#issuecomment-1371240097, or unsubscribe https://github.com/notifications/unsubscribe-auth/A437GHRKDW46L7G2KNQEKS3WQW2FHANCNFSM6AAAAAATP6FMMU . You are receiving this because you are subscribed to this thread.Message ID: @.***>
Please update it to use a fixed vector instead — make pattern matching the focus, not command line shenanigans smile
I'm of course also fine doing this myself, just let me know. We can close this PR and I'll put something else up eventually.
Let's close this for now — I think the example should be rewritten to not use the arguments at all since that's just extra noise.