Skip to content

Commit d8fb322

Browse files
author
Eugene Bulkin
committed
Clean up std::ascii sub-level docs.
* Change `utf8` variable names to `non_ascii` to be more clear, since ASCII and UTF-8 are compatible. * Fix `EscapeDefault` struct description to follow the typical iterator method format with a link to the generating function. * Add more `escape_default` examples to cover every case mentioned in the function description itself.
1 parent 40feadb commit d8fb322

File tree

1 file changed

+44
-8
lines changed

1 file changed

+44
-8
lines changed

src/libstd/ascii.rs

Lines changed: 44 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ pub trait AsciiExt {
5353
/// use std::ascii::AsciiExt;
5454
///
5555
/// let ascii = 'a';
56-
/// let utf8 = '❤';
56+
/// let non_ascii = '❤';
5757
/// let int_ascii = 97;
5858
///
5959
/// assert!(ascii.is_ascii());
60-
/// assert!(!utf8.is_ascii());
60+
/// assert!(!non_ascii.is_ascii());
6161
/// assert!(int_ascii.is_ascii());
6262
/// ```
6363
#[stable(feature = "rust1", since = "1.0.0")]
@@ -79,11 +79,11 @@ pub trait AsciiExt {
7979
/// use std::ascii::AsciiExt;
8080
///
8181
/// let ascii = 'a';
82-
/// let utf8 = '❤';
82+
/// let non_ascii = '❤';
8383
/// let int_ascii = 97;
8484
///
8585
/// assert_eq!('A', ascii.to_ascii_uppercase());
86-
/// assert_eq!('❤', utf8.to_ascii_uppercase());
86+
/// assert_eq!('❤', non_ascii.to_ascii_uppercase());
8787
/// assert_eq!(65, int_ascii.to_ascii_uppercase());
8888
/// ```
8989
///
@@ -108,11 +108,11 @@ pub trait AsciiExt {
108108
/// use std::ascii::AsciiExt;
109109
///
110110
/// let ascii = 'A';
111-
/// let utf8 = '❤';
111+
/// let non_ascii = '❤';
112112
/// let int_ascii = 65;
113113
///
114114
/// assert_eq!('a', ascii.to_ascii_lowercase());
115-
/// assert_eq!('❤', utf8.to_ascii_lowercase());
115+
/// assert_eq!('❤', non_ascii.to_ascii_lowercase());
116116
/// assert_eq!(97, int_ascii.to_ascii_lowercase());
117117
/// ```
118118
///
@@ -934,8 +934,12 @@ impl AsciiExt for char {
934934
}
935935
}
936936

937-
/// An iterator over the escaped version of a byte, constructed via
938-
/// `std::ascii::escape_default`.
937+
/// An iterator over the escaped version of a byte.
938+
///
939+
/// This `struct` is created by the [`escape_default`] function. See its
940+
/// documentation for more.
941+
///
942+
/// [`escape_default`]: fn.escape_default.html
939943
#[stable(feature = "rust1", since = "1.0.0")]
940944
pub struct EscapeDefault {
941945
range: Range<usize>,
@@ -966,6 +970,38 @@ pub struct EscapeDefault {
966970
///
967971
/// assert_eq!(b'\\', escaped.next().unwrap());
968972
/// assert_eq!(b't', escaped.next().unwrap());
973+
///
974+
/// let mut escaped = ascii::escape_default(b'\r');
975+
///
976+
/// assert_eq!(b'\\', escaped.next().unwrap());
977+
/// assert_eq!(b'r', escaped.next().unwrap());
978+
///
979+
/// let mut escaped = ascii::escape_default(b'\n');
980+
///
981+
/// assert_eq!(b'\\', escaped.next().unwrap());
982+
/// assert_eq!(b'n', escaped.next().unwrap());
983+
///
984+
/// let mut escaped = ascii::escape_default(b'\'');
985+
///
986+
/// assert_eq!(b'\\', escaped.next().unwrap());
987+
/// assert_eq!(b'\'', escaped.next().unwrap());
988+
///
989+
/// let mut escaped = ascii::escape_default(b'"');
990+
///
991+
/// assert_eq!(b'\\', escaped.next().unwrap());
992+
/// assert_eq!(b'"', escaped.next().unwrap());
993+
///
994+
/// let mut escaped = ascii::escape_default(b'\\');
995+
///
996+
/// assert_eq!(b'\\', escaped.next().unwrap());
997+
/// assert_eq!(b'\\', escaped.next().unwrap());
998+
///
999+
/// let mut escaped = ascii::escape_default(b'\x9d');
1000+
///
1001+
/// assert_eq!(b'\\', escaped.next().unwrap());
1002+
/// assert_eq!(b'x', escaped.next().unwrap());
1003+
/// assert_eq!(b'9', escaped.next().unwrap());
1004+
/// assert_eq!(b'd', escaped.next().unwrap());
9691005
/// ```
9701006
#[stable(feature = "rust1", since = "1.0.0")]
9711007
pub fn escape_default(c: u8) -> EscapeDefault {

0 commit comments

Comments
 (0)