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

Libz blitz/use question mark instead of unwrap in examples #141

Closed
wants to merge 4 commits into from
Closed

Libz blitz/use question mark instead of unwrap in examples #141

wants to merge 4 commits into from

Conversation

muzikmoe
Copy link
Contributor

Should resolve #129

Copy link

@KodrAus KodrAus left a comment

Choose a reason for hiding this comment

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

Thanks @muzikmoe! I think we should only show the body of your new fallible methods in the docs, I've left an example of how we can do this.

You can also always run cargo doc --no-deps --open locally to quickly view the new docs you're working on.

src/lib.rs Outdated
//!
//! let mut bugfix_release = Version::parse("1.0.0").unwrap();
//! bugfix_release.increment_patch();
//! fn try_increment_patch() -> Result<(), Box<Error>> {
Copy link

Choose a reason for hiding this comment

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

I think we should hide the main function and signature of try_increment_patch so there's less noise in the examples. You can do this by adding a # at the start of a doc test line. Like:

//! # try_main() -> Result<(), Box<Error>> {
//! let mut bugfix_release = Version::parse("1.0.0")?;
//! ...
//! # Ok(())
//! # }
//! # fn main() { try_main().unwrap(); }

That way you only see the body of the try_main function, but the ? magically works.

src/lib.rs Outdated
//! use std::error::Error;
//!
//! fn try_compare() -> Result<(), Box<Error>> {
//!
Copy link

Choose a reason for hiding this comment

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

This is a bit of a bit, but once we hide the method signatures in this example we'll need to remove this newline, otherwise the docs will have an empty line in them too.

@muzikmoe
Copy link
Contributor Author

rebased.
check out #144

@muzikmoe muzikmoe closed this Oct 26, 2017
@muzikmoe muzikmoe deleted the libz_blitz/Use_question_mark_instead_of_unwrap_in_examples branch October 26, 2017 09:02
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.

Use ? instead of unwrap in examples
2 participants