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

doc: improve Option::map example #25920

Merged
merged 1 commit into from
Jun 2, 2015
Merged

doc: improve Option::map example #25920

merged 1 commit into from
Jun 2, 2015

Conversation

tshepang
Copy link
Member

No description provided.

@rust-highfive
Copy link
Collaborator

r? @alexcrichton

(rust_highfive has picked a reviewer for you, use r? to override)

@@ -411,7 +411,9 @@ impl<T> Option<T> {
/// ```
/// let num_as_str: Option<String> = Some("10".to_string());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this even being made into a String?

@Gankra
Copy link
Contributor

Gankra commented May 31, 2015

It's not clear to me that this really "improves" anything. It just makes the example more complicated.

@tshepang
Copy link
Member Author

num_as_int tells me the string 10 is now represented as the int 10. This is more sensible than checking the length of that string.

It's also nice to do an assert there, so we actually make use of those bindings, instead of just assign values.

BTW, feel free to improve this example.

@Gankra
Copy link
Contributor

Gankra commented Jun 1, 2015

I agree the variable names are unfortunate. How about:

/// let maybe_some_string = Some("hello!".to_string());
/// let maybe_some_len = maybe_some_string.map(|s| s.len());
///
/// assert_eq!(maybe_some_len, Some(6));

@tshepang
Copy link
Member Author

tshepang commented Jun 1, 2015

nice suggestion... done!

@Gankra
Copy link
Contributor

Gankra commented Jun 1, 2015

@bors r+ rollup

@bors
Copy link
Contributor

bors commented Jun 1, 2015

📌 Commit 8221715 has been approved by Gankro

Manishearth added a commit to Manishearth/rust that referenced this pull request Jun 2, 2015
bors added a commit that referenced this pull request Jun 2, 2015
@bors bors merged commit 8221715 into rust-lang:master Jun 2, 2015
@tshepang tshepang deleted the option-map-example branch June 2, 2015 11:37
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

Successfully merging this pull request may close these issues.

5 participants