Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

options2: unclear what to do and why #1990

Open
Fxlr8 opened this issue Jun 9, 2024 · 2 comments
Open

options2: unclear what to do and why #1990

Fxlr8 opened this issue Jun 9, 2024 · 2 comments

Comments

@Fxlr8
Copy link

Fxlr8 commented Jun 9, 2024

Hello Rustlings Team,

First of all thank you for this project. It was really fun solving it so far. I got really stuck and scratching my head at this one and I decided to ask you for an improvement.

    fn simple_option() {
        let target = "rustlings";
        let optional_target = Some(target);

        // TODO: Make this an if let statement whose value is "Some" type
        word = optional_target {
            assert_eq!(word, target);
        }
    }

Looks like this excercise is trying to show how to use Option<T> type in Rust. Currently, the exercise seems somewhat forced and does not effectively demonstrate the real-world use cases of the Option type.

We start with a "rustlings" string literal and wrap it in optional_target. Then the comment asks us to Make this an if let statement whose value is "Some" type (which is a riddle by itself) providing us with some convoluted assertion. I am just learning Rust and have never seen this type before. If that task had some real-world scenario showing us why Option type is useful (for example safe parsing of data) that would really help.

@mo8it
Copy link
Contributor

mo8it commented Jul 4, 2024

I agree this part of the exercise is weird. Do you have an idea how to improve it? We should still teach about the if-let statement though. You are welcome to open a PR :D

@Nahor
Copy link
Contributor

Nahor commented Jul 5, 2024

One problem is that it kind of looks like valid code. Coming from C++, Rust has some "weird" expressions (e.g. let ... else ... ;"). So when I first saw that code, my first thought was "what kind of Rust specific expression is that?", instead of "something is missing".

More specifically, it looks like a "normal" assignment where the rhs is optional_target{...} and so my thoughts weres like "are we creating a sort of a struct value of type optional_target?" and "are we creating a closure-like thing?".

Maybe be something like:

/* `if let` expression = optional_target*/ {
   assert_eq!(word, target);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants