Skip to content

Commit ec18991

Browse files
committed
Add links to std::char::REPLACEMENT_CHARACTER from docs.
There are a few places where we mention the replacement character in the docs, and it could be helpful for users to utilize the constant which is available in the standard library, so let’s link to it!
1 parent 0aa8d03 commit ec18991

File tree

6 files changed

+20
-9
lines changed

6 files changed

+20
-9
lines changed

src/liballoc/string.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -519,10 +519,11 @@ impl String {
519519
/// between the two. Not all byte slices are valid strings, however: strings
520520
/// are required to be valid UTF-8. During this conversion,
521521
/// `from_utf8_lossy()` will replace any invalid UTF-8 sequences with
522-
/// `U+FFFD REPLACEMENT CHARACTER`, which looks like this: �
522+
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD], which looks like this: �
523523
///
524524
/// [`u8`]: ../../std/primitive.u8.html
525525
/// [byteslice]: ../../std/primitive.slice.html
526+
/// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html
526527
///
527528
/// If you are sure that the byte slice is valid UTF-8, and you don't want
528529
/// to incur the overhead of the conversion, there is an unsafe version
@@ -621,14 +622,15 @@ impl String {
621622
}
622623

623624
/// Decode a UTF-16 encoded slice `v` into a `String`, replacing
624-
/// invalid data with the replacement character (U+FFFD).
625+
/// invalid data with [the replacement character (`U+FFFD`)][U+FFFD].
625626
///
626627
/// Unlike [`from_utf8_lossy`] which returns a [`Cow<'a, str>`],
627628
/// `from_utf16_lossy` returns a `String` since the UTF-16 to UTF-8
628629
/// conversion requires a memory allocation.
629630
///
630631
/// [`from_utf8_lossy`]: #method.from_utf8_lossy
631632
/// [`Cow<'a, str>`]: ../borrow/enum.Cow.html
633+
/// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html
632634
///
633635
/// # Examples
634636
///

src/libcore/str/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,10 @@ impl Utf8Error {
244244
/// The length provided is that of the invalid byte sequence
245245
/// that starts at the index given by `valid_up_to()`.
246246
/// Decoding should resume after that sequence
247-
/// (after inserting a U+FFFD REPLACEMENT CHARACTER) in case of lossy decoding.
247+
/// (after inserting a [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD]) in case of
248+
/// lossy decoding.
249+
///
250+
/// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html
248251
#[stable(feature = "utf8_error_error_len", since = "1.20.0")]
249252
pub fn error_len(&self) -> Option<usize> {
250253
self.error_len.map(|len| len as usize)

src/libstd/ffi/c_str.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,9 @@ impl CStr {
11751175
/// If the contents of the `CStr` are valid UTF-8 data, this
11761176
/// function will return a [`Cow`]`::`[`Borrowed`]`(`[`&str`]`)`
11771177
/// with the the corresponding [`&str`] slice. Otherwise, it will
1178-
/// replace any invalid UTF-8 sequences with `U+FFFD REPLACEMENT
1179-
/// CHARACTER` and return a [`Cow`]`::`[`Owned`]`(`[`String`]`)`
1180-
/// with the result.
1178+
/// replace any invalid UTF-8 sequences with
1179+
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD] and return a
1180+
/// [`Cow`]`::`[`Owned`]`(`[`String`]`)` with the result.
11811181
///
11821182
/// > **Note**: This method is currently implemented to check for validity
11831183
/// > after a constant-time cast, but it is planned to alter its definition
@@ -1189,6 +1189,7 @@ impl CStr {
11891189
/// [`Owned`]: ../borrow/enum.Cow.html#variant.Owned
11901190
/// [`str`]: ../primitive.str.html
11911191
/// [`String`]: ../string/struct.String.html
1192+
/// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html
11921193
///
11931194
/// # Examples
11941195
///

src/libstd/ffi/os_str.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -520,10 +520,12 @@ impl OsStr {
520520

521521
/// Converts an `OsStr` to a [`Cow`]`<`[`str`]`>`.
522522
///
523-
/// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
523+
/// Any non-Unicode sequences are replaced with
524+
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD].
524525
///
525526
/// [`Cow`]: ../../std/borrow/enum.Cow.html
526527
/// [`str`]: ../../std/primitive.str.html
528+
/// [U+FFFD]: ../../std/char/constant.REPLACEMENT_CHARACTER.html
527529
///
528530
/// # Examples
529531
///

src/libstd/path.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1737,9 +1737,11 @@ impl Path {
17371737

17381738
/// Converts a `Path` to a [`Cow<str>`].
17391739
///
1740-
/// Any non-Unicode sequences are replaced with U+FFFD REPLACEMENT CHARACTER.
1740+
/// Any non-Unicode sequences are replaced with
1741+
/// [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD].
17411742
///
17421743
/// [`Cow<str>`]: ../borrow/enum.Cow.html
1744+
/// [U+FFFD]: ../char/constant.REPLACEMENT_CHARACTER.html
17431745
///
17441746
/// # Examples
17451747
///

src/libstd/sys/windows/ext/ffi.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//!
3232
//! If Rust code *does* need to look into those strings, it can
3333
//! convert them to valid UTF-8, possibly lossily, by substituting
34-
//! invalid sequences with U+FFFD REPLACEMENT CHARACTER, as is
34+
//! invalid sequences with [`U+FFFD REPLACEMENT CHARACTER`][U+FFFD], as is
3535
//! conventionally done in other Rust APIs that deal with string
3636
//! encodings.
3737
//!
@@ -65,6 +65,7 @@
6565
//! [`from_wide`]: trait.OsStringExt.html#tymethod.from_wide
6666
//! [`encode_wide`]: trait.OsStrExt.html#tymethod.encode_wide
6767
//! [`collect`]: ../../../iter/trait.Iterator.html#method.collect
68+
//! [U+FFFD]: ../../../char/constant.REPLACEMENT_CHARACTER.html
6869
6970
#![stable(feature = "rust1", since = "1.0.0")]
7071

0 commit comments

Comments
 (0)