Skip to content

Write a bunch of docs for char #28852

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 1 commit into from
Oct 7, 2015
Merged

Conversation

steveklabnik
Copy link
Member

Mostly adding examples, and reformatting for consistency.

@rust-highfive
Copy link
Contributor

r? @nikomatsakis

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

@Gankra
Copy link
Contributor

Gankra commented Oct 5, 2015

cc @SimonSapin

/// * `a-z`
/// * `A-Z`
///
/// For a more comprehensive understanding of 'digit', see [``][is_numeric].
Copy link
Member

Choose a reason for hiding this comment

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

link doesn't have a body

@steveklabnik steveklabnik force-pushed the doc_char branch 2 times, most recently from 7fb7a95 to d1a917a Compare October 5, 2015 22:32
///
/// assert_eq!(c.to_uppercase().next(), Some('C'));
///
/// // 日本語 does not have case
Copy link
Member

Choose a reason for hiding this comment

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

The comment appears as three glyphs for me, but the character is one. Intentional?

Similar stuff happens in other Han/Kanji examples above.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, as the three glyphs are how you write "Japanese" and "Chinese". I thought that it would be good to write them in their own scripts, given that we're in a crate based around Unicode. Of course, maybe that means I should be using "Türkçe" too, come to think of it.

Copy link
Member

Choose a reason for hiding this comment

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

Oh! Probably should mention the script name, not language name (Japanese, for one, has 3+ scripts), and romanize it too because in this case it looks like it's supposed to be the same as the character below.

Copy link
Member Author

Choose a reason for hiding this comment

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

Since case is a property of a language, and not neccesarily a script, as you mention, I was using the language name, but yeah, maybe that's just too confusing.

Copy link
Contributor

Choose a reason for hiding this comment

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

One difficulty is that 漢字 (the name of the writing system / script) is romanized differently depending on which language’s pronunciation you use. So maybe like this, to avoid picking sides?

/// // 漢字 (Kanji / Hanji) does not have case

Copy link
Contributor

Choose a reason for hiding this comment

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

Since case is a property of a language, and not necessarily a script

Is it? Is there any script that has case in one language but not in another language?

Choose a reason for hiding this comment

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

One other thing is that Japanese' Unicode representation includes special latin scripts which do have upper and lower case forms.

@Manishearth
Copy link
Member

r=me with nits, though SImon should probably have a look first.

/// * Single quote is escaped as `\'`.
/// * Double quote is escaped as `\"`.
/// * Backslash is escaped as `\\`.
/// * Any character in the range `0x20` .. `0x7e` inclusive is not escaped.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe mention that this is the range of "printable" characters in ASCII.

@SimonSapin
Copy link
Contributor

All done reviewing. Thanks for the polish, Steve! This kind of work makes the difference between good and great documentation.

@steveklabnik
Copy link
Member Author

@SimonSapin 😄

I've done everything except @Manishearth's 'radix' bit, so please feel free to re-review those fixes to make sure they work.

@steveklabnik
Copy link
Member Author

Hmm, can't tell why the build failed here, is it just buried in the output somwhere?

@SimonSapin
Copy link
Contributor

👍

/// let c = 'Δ';
/// assert!(!c.is_lowercase());
///
/// // The various Chinese languages do not have case, and so:
Copy link
Member

Choose a reason for hiding this comment

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

s/language/script

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm this is an interesting question, I guess it is a property of a script and not a language

@Manishearth
Copy link
Member

nitpick: case is a property of the script, not just the language. For example, capitalization if followed in romaji (Romanized Japanese). Otherwise lgtm

@steveklabnik steveklabnik force-pushed the doc_char branch 2 times, most recently from f7a32e5 to 78a71fa Compare October 6, 2015 12:45
@steveklabnik
Copy link
Member Author

still have to do the radix bit, but fixed everything else. I wonder if the tests will pass this time, I verified that they work locally, and still can't see where the error is on travis.

@@ -195,21 +253,29 @@ impl char {
#[inline]
pub fn escape_unicode(self) -> EscapeUnicode { C::escape_unicode(self) }

/// Returns an iterator that yields the 'default' ASCII and
/// C++11-like literal escape of a character, as `char`s.
/// Returns an iterator of that yields the literal escape code of a `char`.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this just be "iterator that"?

Copy link
Member Author

Choose a reason for hiding this comment

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

nice catch

@@ -234,29 +300,69 @@ impl char {
#[inline]
pub fn escape_default(self) -> EscapeDefault { C::escape_default(self) }

/// Returns the number of bytes this character would need if encoded in
/// UTF-8.
/// Returns the number of bytes the character this `char` would need if encoded in UTF-8.
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this just be "bytes this char would need"?

Copy link
Member Author

Choose a reason for hiding this comment

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

no, because the encoding really matters, it's not a well-formed statement otherwise.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I meant that the full sentence seems like it should be:

Returns the number of bytes this `char` would need if encoded in UTF-8.

Copy link
Member Author

Choose a reason for hiding this comment

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

ahhhh

@steveklabnik steveklabnik force-pushed the doc_char branch 3 times, most recently from 6858e83 to 16b2250 Compare October 6, 2015 13:46
/// let result = thread::spawn(|| {
/// let d = '1';
///
/// d.is_digit(37);
Copy link
Member

Choose a reason for hiding this comment

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

The indentation here looks like 2 spaces instead of 4, also perhaps this could have something like // this panics and the test could be annotated with should_panic?

Copy link
Member Author

Choose a reason for hiding this comment

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

This test does not actually panic though, as we spin up a thread and check the error.

(the spacing is my bad though)

Copy link
Member

Choose a reason for hiding this comment

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

True but it seems unidiomatic to spawn a thread in an example just to show that it fails? It seems like it may be distracting in terms of reading...

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh, I see, change to that. I thought this was the preferred way to do it, but I guess I can change it if you'd prefer. We should have a good way to visually indicate this in rustdoc too...

@steveklabnik
Copy link
Member Author

So both

$  make check-stage2-doc-crate-rustc_unicode
$  make check-stage2-doc-crate-std -j4

pass locally for me. So unsure about travis :/ @alexcrichton said he thinks it's due to the literal null in the source, but then not sure why it works for me.

@alexcrichton
Copy link
Member

Ah sorry, right, it was make doc/std/index.html that was causing problems on travis

@steveklabnik
Copy link
Member Author

The error message is amazing

rustdoc: doc/std/index.html
thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: NulError(72, [60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 114, 117, 115, 116, 116, 101, 115, 116, 39, 62, 102, 110, 32, 109, 97, 105, 110, 40, 41, 32, 123, 10, 32, 32, 32, 32, 47, 47, 32, 78, 85, 76, 76, 44, 32, 85, 43, 48, 48, 48, 48, 10, 32, 32, 32, 32, 108, 101, 116, 32, 99, 32, 61, 32, 38, 35, 51, 57, 59, 0, 38, 35, 51, 57, 59, 59, 10, 32, 32, 32, 32, 97, 115, 115, 101, 114, 116, 33, 40, 99, 46, 105, 115, 95, 99, 111, 110, 116, 114, 111, 108, 40, 41, 41, 59, 10, 32, 32, 32, 32, 10, 32, 32, 32, 32, 108, 101, 116, 32, 99, 32, 61, 32, 38, 35, 51, 57, 59, 113, 38, 35, 51, 57, 59, 59, 10, 32, 32, 32, 32, 97, 115, 115, 101, 114, 116, 33, 40, 33, 99, 46, 105, 115, 95, 99, 111, 110, 116, 114, 111, 108, 40, 41, 41, 59, 10, 32, 32, 32, 32, 10, 125, 60, 47, 115, 112, 97, 110, 62, 60, 112, 114, 101, 32, 99, 108, 97, 115, 115, 61, 39, 114, 117, 115, 116, 32, 114, 117, 115, 116, 45, 101, 120, 97, 109, 112, 108, 101, 45, 114, 101, 110, 100, 101, 114, 101, 100, 39, 62, 10, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 99, 111, 109, 109, 101, 110, 116, 39, 62, 47, 47, 32, 78, 85, 76, 76, 44, 32, 85, 43, 48, 48, 48, 48, 60, 47, 115, 112, 97, 110, 62, 10, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 107, 119, 39, 62, 108, 101, 116, 60, 47, 115, 112, 97, 110, 62, 32, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 105, 100, 101, 110, 116, 39, 62, 99, 60, 47, 115, 112, 97, 110, 62, 32, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 111, 112, 39, 62, 61, 60, 47, 115, 112, 97, 110, 62, 32, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 115, 116, 114, 105, 110, 103, 39, 62, 38, 35, 51, 57, 59, 0, 38, 35, 51, 57, 59, 60, 47, 115, 112, 97, 110, 62, 59, 10, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 109, 97, 99, 114, 111, 39, 62, 97, 115, 115, 101, 114, 116, 60, 47, 115, 112, 97, 110, 62, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 109, 97, 99, 114, 111, 39, 62, 33, 60, 47, 115, 112, 97, 110, 62, 40, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 105, 100, 101, 110, 116, 39, 62, 99, 60, 47, 115, 112, 97, 110, 62, 46, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 105, 100, 101, 110, 116, 39, 62, 105, 115, 95, 99, 111, 110, 116, 114, 111, 108, 60, 47, 115, 112, 97, 110, 62, 40, 41, 41, 59, 10, 10, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 107, 119, 39, 62, 108, 101, 116, 60, 47, 115, 112, 97, 110, 62, 32, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 105, 100, 101, 110, 116, 39, 62, 99, 60, 47, 115, 112, 97, 110, 62, 32, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 111, 112, 39, 62, 61, 60, 47, 115, 112, 97, 110, 62, 32, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 115, 116, 114, 105, 110, 103, 39, 62, 38, 35, 51, 57, 59, 113, 38, 35, 51, 57, 59, 60, 47, 115, 112, 97, 110, 62, 59, 10, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 109, 97, 99, 114, 111, 39, 62, 97, 115, 115, 101, 114, 116, 60, 47, 115, 112, 97, 110, 62, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 109, 97, 99, 114, 111, 39, 62, 33, 60, 47, 115, 112, 97, 110, 62, 40, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 111, 112, 39, 62, 33, 60, 47, 115, 112, 97, 110, 62, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 105, 100, 101, 110, 116, 39, 62, 99, 60, 47, 115, 112, 97, 110, 62, 46, 60, 115, 112, 97, 110, 32, 99, 108, 97, 115, 115, 61, 39, 105, 100, 101, 110, 116, 39, 62, 105, 115, 95, 99, 111, 110, 116, 114, 111, 108, 60, 47, 115, 112, 97, 110, 62, 40, 41, 41, 59, 60, 47, 112, 114, 101, 62, 10])', src/libcore/result.rs:736

Looks like I'll have to remove the NULL for now, and file a rustdoc bug

Mostly adding examples, and reformatting for consistency.
@steveklabnik
Copy link
Member Author

okay, travis passed. Everyone happy now? :)

@SimonSapin
Copy link
Contributor

Looks good to me.

@alexcrichton
Copy link
Member

@bors: r+ 51097fc

@bors
Copy link
Collaborator

bors commented Oct 7, 2015

⌛ Testing commit 51097fc with merge babe953...

bors added a commit that referenced this pull request Oct 7, 2015
Mostly adding examples, and reformatting for consistency.
@bors bors merged commit 51097fc into rust-lang:master Oct 7, 2015
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.

10 participants