Skip to content

Commit

Permalink
Rollup merge of #41243 - projektir:prim_str_docs, r=GuillaumeGomez
Browse files Browse the repository at this point in the history
Minor nits in primitive str

Some minor updates to linking, added some links, doc format, etc.

r? @GuillaumeGomez
  • Loading branch information
TimNN authored Apr 12, 2017
2 parents 1dd9801 + ed7b6c3 commit d4d35cf
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 17 deletions.
37 changes: 24 additions & 13 deletions src/libcollections/str.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,10 @@ impl str {

/// Returns a subslice of `str`.
///
/// This is the non-panicking alternative to indexing the `str`. Returns `None` whenever
/// equivalent indexing operation would panic.
/// This is the non-panicking alternative to indexing the `str`. Returns
/// [`None`] whenever equivalent indexing operation would panic.
///
/// [`None`]: option/enum.Option.html#variant.None
///
/// # Examples
///
Expand All @@ -346,8 +348,10 @@ impl str {

/// Returns a mutable subslice of `str`.
///
/// This is the non-panicking alternative to indexing the `str`. Returns `None` whenever
/// equivalent indexing operation would panic.
/// This is the non-panicking alternative to indexing the `str`. Returns
/// [`None`] whenever equivalent indexing operation would panic.
///
/// [`None`]: option/enum.Option.html#variant.None
///
/// # Examples
///
Expand Down Expand Up @@ -570,7 +574,7 @@ impl str {
core_str::StrExt::split_at_mut(self, mid)
}

/// Returns an iterator over the `char`s of a string slice.
/// Returns an iterator over the [`char`]s of a string slice.
///
/// As a string slice consists of valid UTF-8, we can iterate through a
/// string slice by [`char`]. This method returns such an iterator.
Expand Down Expand Up @@ -1657,13 +1661,13 @@ impl str {

/// Parses this string slice into another type.
///
/// Because `parse()` is so general, it can cause problems with type
/// inference. As such, `parse()` is one of the few times you'll see
/// Because `parse` is so general, it can cause problems with type
/// inference. As such, `parse` is one of the few times you'll see
/// the syntax affectionately known as the 'turbofish': `::<>`. This
/// helps the inference algorithm understand specifically which type
/// you're trying to parse into.
///
/// `parse()` can parse any type that implements the [`FromStr`] trait.
/// `parse` can parse any type that implements the [`FromStr`] trait.
///
/// [`FromStr`]: str/trait.FromStr.html
///
Expand Down Expand Up @@ -1746,7 +1750,7 @@ impl str {
///
/// `replacen` creates a new [`String`], and copies the data from this string slice into it.
/// While doing so, it attempts to find matches of a pattern. If it finds any, it
/// replaces them with the replacement string slice at most `N` times.
/// replaces them with the replacement string slice at most `count` times.
///
/// [`String`]: string/struct.String.html
///
Expand Down Expand Up @@ -1892,33 +1896,40 @@ impl str {
return s;
}

/// Escapes each char in `s` with `char::escape_debug`.
/// Escapes each char in `s` with [`char::escape_debug`].
///
/// [`char::escape_debug`]: primitive.char.html#method.escape_debug
#[unstable(feature = "str_escape",
reason = "return type may change to be an iterator",
issue = "27791")]
pub fn escape_debug(&self) -> String {
self.chars().flat_map(|c| c.escape_debug()).collect()
}

/// Escapes each char in `s` with `char::escape_default`.
/// Escapes each char in `s` with [`char::escape_default`].
///
/// [`char::escape_default`]: primitive.char.html#method.escape_default
#[unstable(feature = "str_escape",
reason = "return type may change to be an iterator",
issue = "27791")]
pub fn escape_default(&self) -> String {
self.chars().flat_map(|c| c.escape_default()).collect()
}

/// Escapes each char in `s` with `char::escape_unicode`.
/// Escapes each char in `s` with [`char::escape_unicode`].
///
/// [`char::escape_unicode`]: primitive.char.html#method.escape_unicode
#[unstable(feature = "str_escape",
reason = "return type may change to be an iterator",
issue = "27791")]
pub fn escape_unicode(&self) -> String {
self.chars().flat_map(|c| c.escape_unicode()).collect()
}

/// Converts a `Box<str>` into a [`String`] without copying or allocating.
/// Converts a [`Box<str>`] into a [`String`] without copying or allocating.
///
/// [`String`]: string/struct.String.html
/// [`Box<str>`]: boxed/struct.Box.html
///
/// # Examples
///
Expand Down
8 changes: 4 additions & 4 deletions src/libstd/primitive_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ mod prim_slice { }
///
/// This documentation describes a number of methods and trait implementations
/// on the `str` type. For technical reasons, there is additional, separate
/// documentation in [the `std::str` module](str/index.html) as well.
/// documentation in the [`std::str`](str/index.html) module as well.
///
/// # Examples
///
Expand All @@ -425,7 +425,7 @@ mod prim_slice { }
/// # Representation
///
/// A `&str` is made up of two components: a pointer to some bytes, and a
/// length. You can look at these with the [`.as_ptr`] and [`len`] methods:
/// length. You can look at these with the [`as_ptr`] and [`len`] methods:
///
/// ```
/// use std::slice;
Expand All @@ -452,11 +452,11 @@ mod prim_slice { }
/// assert_eq!(s, Ok(story));
/// ```
///
/// [`.as_ptr`]: #method.as_ptr
/// [`as_ptr`]: #method.as_ptr
/// [`len`]: #method.len
///
/// Note: This example shows the internals of `&str`. `unsafe` should not be
/// used to get a string slice under normal circumstances. Use `.as_slice()`
/// used to get a string slice under normal circumstances. Use `as_slice`
/// instead.
#[stable(feature = "rust1", since = "1.0.0")]
mod prim_str { }
Expand Down

0 comments on commit d4d35cf

Please sign in to comment.