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

Add examples for Checked[Add|Sub|Mul|Div] #15930

Closed
wants to merge 1 commit into from

Conversation

nham
Copy link
Contributor

@nham nham commented Jul 23, 2014

No description provided.

/// let x = 5u16.checked_add(&65530u16);
/// assert!(x.is_some() && x.unwrap() == 65535u16);
/// assert!(6u16.checked_add(&65530u16).is_none());
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

In this example and the examples below I think you should be able to leave off the suffix on literals except for the receiver of the checked_foo method. In other words, when unwrapping I don't think you'll need the suffix and when passing arguments I don't think you'll need the suffix.

Copy link
Contributor

Choose a reason for hiding this comment

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

The equality assert should be simplified to an assert_eq (which also lets us drop the variable), as in

assert_eq!(5u16.checked_add(&65530), Some(65535));

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good call. I'm not sure why I added those.

@lilyball
Copy link
Contributor

Aesthetically, I'd prefer it if the is_none() asserts were also converted to assert_eq!() (because it would line up nicely with the previous assert_eq!(), but otherwise, LGTM.

@nham
Copy link
Contributor Author

nham commented Jul 23, 2014

Done

@lilyball
Copy link
Contributor

LGTM. r=me if you squash the commits.

@brson
Copy link
Contributor

brson commented Jul 24, 2014

Thanks for the docs!

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.

4 participants