-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Rustdoc: example of use of assertions #48961
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @steveklabnik (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
@@ -31,6 +31,17 @@ let x = 5; | |||
|
|||
There's some subtlety though! Read on for more details. | |||
|
|||
## Assertions-dedicated macros | |||
|
|||
Of course, `assert!`, `assert_eq!` and `assert_ne` can be used into your examples as in any Rust source code. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, i'm not a fan of this phrasing. How about something like this?
Passing or failing a doctest
Like regular unit tests, regular doctests are considered to "pass" if they compile and run without panicking. So if you want to demonstrate that some computation gives a certain result, the
assert!
family of macros works the same as other Rust code:let foo = "foo"; assert_eq!(foo, "foo");This way, if the computation ever returns something different, the code panics and the doctest fails.
Also, be aware that we like to insert hard line breaks into the docs to keep a single line from running longer than 100 characters. You can use the other sections in this file as a guideline.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll replace the changes.
Also, be aware that we like to insert hard line breaks into the docs to keep a single line from running longer than 100 characters. You can use the other sections in this file as a guideline.
Understood.
Thanks so much! It looks great now. I'll let travis run its course and push this on if it turns green. (Unless @steveklabnik or @GuillaumeGomez have farther comments before then.) |
Nope, looks good to me. But a squash is required here as well. :) |
c8707ec
to
a48224b
Compare
The squash was performed, here, @GuillaumeGomez. |
Thanks! @bors: r+ rollup |
📌 Commit a48224b has been approved by |
…ns, r=GuillaumeGomez Rustdoc: example of use of assertions I added this section at the beginning of the file because it seems to be basic information. Let me know if there's someplace more relevant. See rust-lang#47945.
I added this section at the beginning of the file because it seems to be basic information. Let me know if there's someplace more relevant.
See #47945.