38
38
//! let message = s + " world!";
39
39
//! ```
40
40
//!
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
42
42
//! it. You can do the reverse too.
43
43
//!
44
44
//! ```
@@ -155,17 +155,14 @@ use boxed::Box;
155
155
/// takes_str(&s);
156
156
/// ```
157
157
///
158
- /// [`&str`]: ../../std/primitive.str.html
159
- /// [`Deref`]: ../../std/ops/trait.Deref.html
160
- ///
161
158
/// This will create a [`&str`] from the `String` and pass it in. This
162
159
/// conversion is very inexpensive, and so generally, functions will accept
163
160
/// [`&str`]s as arguments unless they need a `String` for some specific
164
161
/// reason.
165
162
///
166
163
/// 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
169
166
/// `example_func` takes anything that implements the trait. In this case Rust
170
167
/// would need to make two implicit conversions, which Rust doesn't have the
171
168
/// means to do. For that reason, the following example will not compile.
@@ -185,13 +182,13 @@ use boxed::Box;
185
182
///
186
183
/// There are two options that would work instead. The first would be to
187
184
/// 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()`]
189
186
/// to explicitly extract the string slice containing the string. The second
190
187
/// way changes `example_func(&example_string);` to
191
188
/// `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.
195
192
///
196
193
/// # Representation
197
194
///
@@ -287,6 +284,10 @@ use boxed::Box;
287
284
/// ```
288
285
///
289
286
/// 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
290
291
#[ derive( PartialOrd , Eq , Ord ) ]
291
292
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
292
293
pub struct String {
@@ -443,32 +444,22 @@ impl String {
443
444
/// requires that it is valid UTF-8. `from_utf8()` checks to ensure that
444
445
/// the bytes are valid UTF-8, and then does the conversion.
445
446
///
446
- /// [`&str`]: ../../std/primitive.str.html
447
- /// [`u8`]: ../../std/primitive.u8.html
448
- /// [`Vec<u8>`]: ../../std/vec/struct.Vec.html
449
- ///
450
447
/// If you are sure that the byte slice is valid UTF-8, and you don't want
451
448
/// to incur the overhead of the validity check, there is an unsafe version
452
449
/// of this function, [`from_utf8_unchecked`], which has the same behavior
453
450
/// but skips the check.
454
451
///
455
- /// [`from_utf8_unchecked`]: struct.String.html#method.from_utf8_unchecked
456
- ///
457
452
/// This method will take care to not copy the vector, for efficiency's
458
453
/// sake.
459
454
///
460
- /// If you need a `&str` instead of a `String`, consider
455
+ /// If you need a [ `&str`] instead of a `String`, consider
461
456
/// [`str::from_utf8`].
462
457
///
463
- /// [`str::from_utf8`]: ../../std/str/fn.from_utf8.html
464
- ///
465
458
/// The inverse of this method is [`as_bytes`].
466
459
///
467
- /// [`as_bytes`]: #method.as_bytes
468
- ///
469
460
/// # Errors
470
461
///
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
472
463
/// provided bytes are not UTF-8. The vector you moved in is also included.
473
464
///
474
465
/// # Examples
@@ -497,7 +488,14 @@ impl String {
497
488
/// See the docs for [`FromUtf8Error`] for more details on what you can do
498
489
/// with this error.
499
490
///
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
500
497
/// [`FromUtf8Error`]: struct.FromUtf8Error.html
498
+ /// [`Err`]: ../../stdresult/enum.Result.html#variant.Err
501
499
#[ inline]
502
500
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
503
501
pub fn from_utf8 ( vec : Vec < u8 > ) -> Result < String , FromUtf8Error > {
@@ -594,9 +592,11 @@ impl String {
594
592
Cow :: Owned ( res)
595
593
}
596
594
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`]
598
596
/// if `v` contains any invalid data.
599
597
///
598
+ /// [`Err`]: ../../std/result/enum.Result.htlm#variant.Err
599
+ ///
600
600
/// # Examples
601
601
///
602
602
/// Basic usage:
@@ -618,7 +618,7 @@ impl String {
618
618
decode_utf16 ( v. iter ( ) . cloned ( ) ) . collect :: < Result < _ , _ > > ( ) . map_err ( |_| FromUtf16Error ( ( ) ) )
619
619
}
620
620
621
- /// Decode a UTF-16 encoded vector `v` into a string , replacing
621
+ /// Decode a UTF-16 encoded slice `v` into a `String` , replacing
622
622
/// invalid data with the replacement character (U+FFFD).
623
623
///
624
624
/// # Examples
@@ -800,11 +800,12 @@ impl String {
800
800
/// If you do not want this "at least" behavior, see the [`reserve_exact`]
801
801
/// method.
802
802
///
803
- /// [`reserve_exact`]: #method.reserve_exact
804
- ///
805
803
/// # Panics
806
804
///
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
808
809
///
809
810
/// # Examples
810
811
///
@@ -909,7 +910,9 @@ impl String {
909
910
self . vec . shrink_to_fit ( )
910
911
}
911
912
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
913
916
///
914
917
/// # Examples
915
918
///
@@ -990,7 +993,9 @@ impl String {
990
993
991
994
/// Removes the last character from the string buffer and returns it.
992
995
///
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
994
999
///
995
1000
/// # Examples
996
1001
///
@@ -1019,7 +1024,7 @@ impl String {
1019
1024
Some ( ch)
1020
1025
}
1021
1026
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.
1023
1028
///
1024
1029
/// This is an `O(n)` operation, as it requires copying every element in the
1025
1030
/// buffer.
@@ -1389,7 +1394,7 @@ impl String {
1389
1394
/// replaces with the given string, and yields the removed chars.
1390
1395
/// The given string doesn’t need to be the same length as the range.
1391
1396
///
1392
- /// Note: The element range is removed when the `Splice` is dropped,
1397
+ /// Note: The element range is removed when the [ `Splice`] is dropped,
1393
1398
/// even if the iterator is not consumed until the end.
1394
1399
///
1395
1400
/// # Panics
@@ -1398,6 +1403,7 @@ impl String {
1398
1403
/// boundary, or if they're out of bounds.
1399
1404
///
1400
1405
/// [`char`]: ../../std/primitive.char.html
1406
+ /// [`Splice`]: ../../std/string/struct.Splice.html
1401
1407
///
1402
1408
/// # Examples
1403
1409
///
@@ -1450,10 +1456,13 @@ impl String {
1450
1456
}
1451
1457
}
1452
1458
1453
- /// Converts this `String` into a `Box< str>`.
1459
+ /// Converts this `String` into a [ `Box`]`<`[` str`]` >`.
1454
1460
///
1455
1461
/// This will drop any excess capacity.
1456
1462
///
1463
+ /// [`Box`]: ../../std/boxed/struct.Box.html
1464
+ /// [`str`]: ../../std/primitive.str.html
1465
+ ///
1457
1466
/// # Examples
1458
1467
///
1459
1468
/// Basic usage:
0 commit comments