3838//! let message = s + " world!";
3939//! ```
4040//!
41- //! If you have a vector of valid UTF-8 bytes, you can make a `String` out of
41+ //! If you have a vector of valid UTF-8 bytes, you can make a [ `String`] out of
4242//! it. You can do the reverse too.
4343//!
4444//! ```
@@ -155,17 +155,14 @@ use boxed::Box;
155155/// takes_str(&s);
156156/// ```
157157///
158- /// [`&str`]: ../../std/primitive.str.html
159- /// [`Deref`]: ../../std/ops/trait.Deref.html
160- ///
161158/// This will create a [`&str`] from the `String` and pass it in. This
162159/// conversion is very inexpensive, and so generally, functions will accept
163160/// [`&str`]s as arguments unless they need a `String` for some specific
164161/// reason.
165162///
166163/// In certain cases Rust doesn't have enough information to make this
167- /// conversion, known as `Deref` coercion. In the following example a string
168- /// slice `&'a str` implements the trait `TraitExample`, and the function
164+ /// conversion, known as [ `Deref`] coercion. In the following example a string
165+ /// slice [ `&'a str`][`&str`] implements the trait `TraitExample`, and the function
169166/// `example_func` takes anything that implements the trait. In this case Rust
170167/// would need to make two implicit conversions, which Rust doesn't have the
171168/// means to do. For that reason, the following example will not compile.
@@ -185,13 +182,13 @@ use boxed::Box;
185182///
186183/// There are two options that would work instead. The first would be to
187184/// change the line `example_func(&example_string);` to
188- /// `example_func(example_string.as_str());`, using the method `as_str()`
185+ /// `example_func(example_string.as_str());`, using the method [ `as_str()`]
189186/// to explicitly extract the string slice containing the string. The second
190187/// way changes `example_func(&example_string);` to
191188/// `example_func(&*example_string);`. In this case we are dereferencing a
192- /// `String` to a `str`, then referencing the `str` back to `&str`. The
193- /// second way is more idiomatic, however both work to do the conversion
194- /// explicitly rather than relying on the implicit conversion.
189+ /// `String` to a [ `str`][`&str`] , then referencing the [ `str`][ `&str`] back to
190+ /// [`&str`]. The second way is more idiomatic, however both work to do the
191+ /// conversion explicitly rather than relying on the implicit conversion.
195192///
196193/// # Representation
197194///
@@ -287,6 +284,10 @@ use boxed::Box;
287284/// ```
288285///
289286/// Here, there's no need to allocate more memory inside the loop.
287+ ///
288+ /// [`&str`]: ../../std/primitive.str.html
289+ /// [`Deref`]: ../../std/ops/trait.Deref.html
290+ /// [`as_str()`]: struct.String.html#method.as_str
290291#[ derive( PartialOrd , Eq , Ord ) ]
291292#[ stable( feature = "rust1" , since = "1.0.0" ) ]
292293pub struct String {
@@ -443,32 +444,22 @@ impl String {
443444 /// requires that it is valid UTF-8. `from_utf8()` checks to ensure that
444445 /// the bytes are valid UTF-8, and then does the conversion.
445446 ///
446- /// [`&str`]: ../../std/primitive.str.html
447- /// [`u8`]: ../../std/primitive.u8.html
448- /// [`Vec<u8>`]: ../../std/vec/struct.Vec.html
449- ///
450447 /// If you are sure that the byte slice is valid UTF-8, and you don't want
451448 /// to incur the overhead of the validity check, there is an unsafe version
452449 /// of this function, [`from_utf8_unchecked`], which has the same behavior
453450 /// but skips the check.
454451 ///
455- /// [`from_utf8_unchecked`]: struct.String.html#method.from_utf8_unchecked
456- ///
457452 /// This method will take care to not copy the vector, for efficiency's
458453 /// sake.
459454 ///
460- /// If you need a `&str` instead of a `String`, consider
455+ /// If you need a [ `&str`] instead of a `String`, consider
461456 /// [`str::from_utf8`].
462457 ///
463- /// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html
464- ///
465458 /// The inverse of this method is [`as_bytes`].
466459 ///
467- /// [`as_bytes`]: #method.as_bytes
468- ///
469460 /// # Errors
470461 ///
471- /// Returns `Err` if the slice is not UTF-8 with a description as to why the
462+ /// Returns [ `Err`] if the slice is not UTF-8 with a description as to why the
472463 /// provided bytes are not UTF-8. The vector you moved in is also included.
473464 ///
474465 /// # Examples
@@ -497,7 +488,14 @@ impl String {
497488 /// See the docs for [`FromUtf8Error`] for more details on what you can do
498489 /// with this error.
499490 ///
491+ /// [`from_utf8_unchecked`]: struct.String.html#method.from_utf8_unchecked
492+ /// [`&str`]: ../../std/primitive.str.html
493+ /// [`u8`]: ../../std/primitive.u8.html
494+ /// [`Vec<u8>`]: ../../std/vec/struct.Vec.html
495+ /// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html
496+ /// [`as_bytes`]: struct.String.html#method.as_bytes
500497 /// [`FromUtf8Error`]: struct.FromUtf8Error.html
498+ /// [`Err`]: ../../stdresult/enum.Result.html#variant.Err
501499 #[ inline]
502500 #[ stable( feature = "rust1" , since = "1.0.0" ) ]
503501 pub fn from_utf8 ( vec : Vec < u8 > ) -> Result < String , FromUtf8Error > {
@@ -594,9 +592,11 @@ impl String {
594592 Cow :: Owned ( res)
595593 }
596594
597- /// Decode a UTF-16 encoded vector `v` into a `String`, returning `Err`
595+ /// Decode a UTF-16 encoded vector `v` into a `String`, returning [ `Err`]
598596 /// if `v` contains any invalid data.
599597 ///
598+ /// [`Err`]: ../../std/result/enum.Result.htlm#variant.Err
599+ ///
600600 /// # Examples
601601 ///
602602 /// Basic usage:
@@ -618,7 +618,7 @@ impl String {
618618 decode_utf16 ( v. iter ( ) . cloned ( ) ) . collect :: < Result < _ , _ > > ( ) . map_err ( |_| FromUtf16Error ( ( ) ) )
619619 }
620620
621- /// Decode a UTF-16 encoded vector `v` into a string , replacing
621+ /// Decode a UTF-16 encoded slice `v` into a `String` , replacing
622622 /// invalid data with the replacement character (U+FFFD).
623623 ///
624624 /// # Examples
@@ -800,11 +800,12 @@ impl String {
800800 /// If you do not want this "at least" behavior, see the [`reserve_exact`]
801801 /// method.
802802 ///
803- /// [`reserve_exact`]: #method.reserve_exact
804- ///
805803 /// # Panics
806804 ///
807- /// Panics if the new capacity overflows `usize`.
805+ /// Panics if the new capacity overflows [`usize`].
806+ ///
807+ /// [`reserve_exact`]: struct.String.html#method.reserve_exact
808+ /// [`usize`]: ../../std/primitive.usize.html
808809 ///
809810 /// # Examples
810811 ///
@@ -909,7 +910,9 @@ impl String {
909910 self . vec . shrink_to_fit ( )
910911 }
911912
912- /// Appends the given `char` to the end of this `String`.
913+ /// Appends the given [`char`] to the end of this `String`.
914+ ///
915+ /// [`char`]: ../../std/primitive.char.html
913916 ///
914917 /// # Examples
915918 ///
@@ -990,7 +993,9 @@ impl String {
990993
991994 /// Removes the last character from the string buffer and returns it.
992995 ///
993- /// Returns `None` if this `String` is empty.
996+ /// Returns [`None`] if this `String` is empty.
997+ ///
998+ /// [`None`]: ../../std/option/enum.Option.html#variant.None
994999 ///
9951000 /// # Examples
9961001 ///
@@ -1019,7 +1024,7 @@ impl String {
10191024 Some ( ch)
10201025 }
10211026
1022- /// Removes a `char` from this `String` at a byte position and returns it.
1027+ /// Removes a [ `char`] from this `String` at a byte position and returns it.
10231028 ///
10241029 /// This is an `O(n)` operation, as it requires copying every element in the
10251030 /// buffer.
@@ -1389,7 +1394,7 @@ impl String {
13891394 /// replaces with the given string, and yields the removed chars.
13901395 /// The given string doesn’t need to be the same length as the range.
13911396 ///
1392- /// Note: The element range is removed when the `Splice` is dropped,
1397+ /// Note: The element range is removed when the [ `Splice`] is dropped,
13931398 /// even if the iterator is not consumed until the end.
13941399 ///
13951400 /// # Panics
@@ -1398,6 +1403,7 @@ impl String {
13981403 /// boundary, or if they're out of bounds.
13991404 ///
14001405 /// [`char`]: ../../std/primitive.char.html
1406+ /// [`Splice`]: ../../std/string/struct.Splice.html
14011407 ///
14021408 /// # Examples
14031409 ///
@@ -1450,10 +1456,13 @@ impl String {
14501456 }
14511457 }
14521458
1453- /// Converts this `String` into a `Box< str>`.
1459+ /// Converts this `String` into a [ `Box`]`<`[` str`]` >`.
14541460 ///
14551461 /// This will drop any excess capacity.
14561462 ///
1463+ /// [`Box`]: ../../std/boxed/struct.Box.html
1464+ /// [`str`]: ../../std/primitive.str.html
1465+ ///
14571466 /// # Examples
14581467 ///
14591468 /// Basic usage:
0 commit comments