-
Notifications
You must be signed in to change notification settings - Fork 14.1k
Even moar editing #24273
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
Merged
Merged
Even moar editing #24273
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,47 +1,45 @@ | ||
| % Comments | ||
|
|
||
| Now that we have some functions, it's a good idea to learn about comments. | ||
| Now that we have some functions, it’s a good idea to learn about comments. | ||
| Comments are notes that you leave to other programmers to help explain things | ||
| about your code. The compiler mostly ignores them. | ||
|
|
||
| Rust has two kinds of comments that you should care about: *line comments* | ||
| and *doc comments*. | ||
|
|
||
| ```{rust} | ||
| // Line comments are anything after '//' and extend to the end of the line. | ||
| ```rust | ||
| // Line comments are anything after ‘//’ and extend to the end of the line. | ||
|
|
||
| let x = 5; // this is also a line comment. | ||
|
|
||
| // If you have a long explanation for something, you can put line comments next | ||
| // to each other. Put a space between the // and your comment so that it's | ||
| // to each other. Put a space between the // and your comment so that it’s | ||
| // more readable. | ||
| ``` | ||
|
|
||
| The other kind of comment is a doc comment. Doc comments use `///` instead of | ||
| `//`, and support Markdown notation inside: | ||
|
|
||
| ```{rust} | ||
| /// `hello` is a function that prints a greeting that is personalized based on | ||
| /// the name given. | ||
| /// | ||
| /// # Arguments | ||
| /// | ||
| /// * `name` - The name of the person you'd like to greet. | ||
| ```rust | ||
| /// Adds one to the number given. | ||
| /// | ||
| /// # Examples | ||
| /// | ||
| /// ```rust | ||
| /// let name = "Steve"; | ||
| /// hello(name); // prints "Hello, Steve!" | ||
| /// ``` | ||
| fn hello(name: &str) { | ||
| println!("Hello, {}!", name); | ||
| /// let five = 5; | ||
| /// | ||
| /// assert_eq!(6, add_one(5)); | ||
| /// ``` | ||
| fn add_one(x: i32) -> i32 { | ||
| x + 1 | ||
| } | ||
| ``` | ||
|
|
||
| When writing doc comments, adding sections for any arguments, return values, | ||
| and providing some examples of usage is very, very helpful. Don't worry about | ||
| the `&str`, we'll get to it soon. | ||
| When writing doc comments, providing some examples of usage is very, very | ||
| helpful. You’ll notice we’ve used a new macro here: `assert_eq!`. This compares | ||
| two values, and `panic!`s if they’re not equal to each other. It’s very helpful | ||
| in documentation. There’s another macro, `assert!`, which `panic!`s if the | ||
| value passed to it is `false`. | ||
|
|
||
| You can use the [`rustdoc`](documentation.html) tool to generate HTML documentation | ||
| from these doc comments. | ||
| from these doc comments, and also to run the code examples as tests! | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Out of curiosity, why the switch to a unicode apostrophe? I'm not sure that other contributors to the docs may follow that style if it's harder to type, but I dunno if it makes much of an inconsistency.
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.
it's technically more correct and a very commonly requested thing, I know @dherman really wanted it 😄
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 guess I'm just worried that we'll have to continually make passes through the documentation to update something like this, or I just don't know how to type it!
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 don't plan on doing a mega-edit to update them, it's only because I'm already doing a readthrough of all this that I'm fixing it.
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 would suggest using smartypants, which was designed to do this sort of thing, rather than using untypeable(?) characters in the markdown, especially for common punctuation. The version of hoedown rustdoc uses supports it, so it'd be a matter of adding an extra pass to rustdoc for the book.
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 really miss typographic quotes as well, but I think we ought to be consistent. We should run smartypants at build-time. Hoedown ships with a smartypants binary which we ought to add to the existing rust wrapper.
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.
maybe prefer ASCII is always nice.