Skip to content

Commit 2ea6379

Browse files
authored
Rollup merge of #75782 - GuillaumeGomez:more-links, r=jyn514
Convert core/src/str/pattern.rs to Intra-doc links Part of #75080.
2 parents cb9ef09 + 385a1b2 commit 2ea6379

File tree

1 file changed

+57
-57
lines changed

1 file changed

+57
-57
lines changed

library/core/src/str/pattern.rs

+57-57
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//! # Examples
1313
//!
1414
//! [`Pattern`] is [implemented][pattern-impls] in the stable API for
15-
//! [`&str`], [`char`], slices of [`char`], and functions and closures
15+
//! [`&str`][`str`], [`char`], slices of [`char`], and functions and closures
1616
//! implementing `FnMut(char) -> bool`.
1717
//!
1818
//! ```
@@ -28,13 +28,6 @@
2828
//! assert_eq!(s.find(|c: char| c.is_ascii_punctuation()), Some(35));
2929
//! ```
3030
//!
31-
//! [`&str`]: ../../../std/primitive.str.html
32-
//! [`char`]: ../../../std/primitive.char.html
33-
//! [`str`]: ../../../std/primitive.str.html
34-
//! [`DoubleEndedSearcher`]: trait.DoubleEndedSearcher.html
35-
//! [`Pattern`]: trait.Pattern.html
36-
//! [`ReverseSearcher`]: trait.ReverseSearcher.html
37-
//! [`Searcher`]: trait.Searcher.html
3831
//! [pattern-impls]: trait.Pattern.html#implementors
3932
4033
#![unstable(
@@ -52,13 +45,13 @@ use crate::slice::memchr;
5245
/// A string pattern.
5346
///
5447
/// A `Pattern<'a>` expresses that the implementing type
55-
/// can be used as a string pattern for searching in a `&'a str`.
48+
/// can be used as a string pattern for searching in a [`&'a str`][str].
5649
///
5750
/// For example, both `'a'` and `"aa"` are patterns that
5851
/// would match at index `1` in the string `"baaaab"`.
5952
///
6053
/// The trait itself acts as a builder for an associated
61-
/// `Searcher` type, which does the actual work of finding
54+
/// [`Searcher`] type, which does the actual work of finding
6255
/// occurrences of the pattern in a string.
6356
///
6457
/// Depending on the type of the pattern, the behaviour of methods like
@@ -75,6 +68,7 @@ use crate::slice::memchr;
7568
/// | `&String` | is substring |
7669
///
7770
/// # Examples
71+
///
7872
/// ```
7973
/// // &str
8074
/// assert_eq!("abaaa".find("ba"), Some(1));
@@ -94,9 +88,6 @@ use crate::slice::memchr;
9488
/// assert_eq!("abcdef_z".find(|ch| ch > 'd' && ch < 'y'), Some(4));
9589
/// assert_eq!("abcddd_z".find(|ch| ch > 'd' && ch < 'y'), None);
9690
/// ```
97-
///
98-
/// [`str::find`]: ../../../std/primitive.str.html#method.find
99-
/// [`str::contains`]: ../../../std/primitive.str.html#method.contains
10091
pub trait Pattern<'a>: Sized {
10192
/// Associated searcher for this pattern
10293
type Searcher: Searcher<'a>;
@@ -165,7 +156,7 @@ pub trait Pattern<'a>: Sized {
165156

166157
// Searcher
167158

168-
/// Result of calling `Searcher::next()` or `ReverseSearcher::next_back()`.
159+
/// Result of calling [`Searcher::next()`] or [`ReverseSearcher::next_back()`].
169160
#[derive(Copy, Clone, Eq, PartialEq, Debug)]
170161
pub enum SearchStep {
171162
/// Expresses that a match of the pattern has been found at
@@ -188,44 +179,47 @@ pub enum SearchStep {
188179
/// matches of a pattern starting from the front (left) of a string.
189180
///
190181
/// It will be implemented by associated `Searcher`
191-
/// types of the `Pattern` trait.
182+
/// types of the [`Pattern`] trait.
192183
///
193184
/// The trait is marked unsafe because the indices returned by the
194-
/// `next()` methods are required to lie on valid utf8 boundaries in
195-
/// the haystack. This enables consumers of this trait to
185+
/// [`next()`][Searcher::next] methods are required to lie on valid utf8
186+
/// boundaries in the haystack. This enables consumers of this trait to
196187
/// slice the haystack without additional runtime checks.
197188
pub unsafe trait Searcher<'a> {
198189
/// Getter for the underlying string to be searched in
199190
///
200-
/// Will always return the same `&str`
191+
/// Will always return the same [`&str`][str].
201192
fn haystack(&self) -> &'a str;
202193

203194
/// Performs the next search step starting from the front.
204195
///
205-
/// - Returns `Match(a, b)` if `haystack[a..b]` matches the pattern.
206-
/// - Returns `Reject(a, b)` if `haystack[a..b]` can not match the
207-
/// pattern, even partially.
208-
/// - Returns `Done` if every byte of the haystack has been visited
196+
/// - Returns [`Match(a, b)`][SearchStep::Match] if `haystack[a..b]` matches
197+
/// the pattern.
198+
/// - Returns [`Reject(a, b)`][SearchStep::Reject] if `haystack[a..b]` can
199+
/// not match the pattern, even partially.
200+
/// - Returns [`Done`][SearchStep::Done] if every byte of the haystack has
201+
/// been visited.
209202
///
210-
/// The stream of `Match` and `Reject` values up to a `Done`
203+
/// The stream of [`Match`][SearchStep::Match] and
204+
/// [`Reject`][SearchStep::Reject] values up to a [`Done`][SearchStep::Done]
211205
/// will contain index ranges that are adjacent, non-overlapping,
212206
/// covering the whole haystack, and laying on utf8 boundaries.
213207
///
214-
/// A `Match` result needs to contain the whole matched pattern,
215-
/// however `Reject` results may be split up into arbitrary
216-
/// many adjacent fragments. Both ranges may have zero length.
208+
/// A [`Match`][SearchStep::Match] result needs to contain the whole matched
209+
/// pattern, however [`Reject`][SearchStep::Reject] results may be split up
210+
/// into arbitrary many adjacent fragments. Both ranges may have zero length.
217211
///
218212
/// As an example, the pattern `"aaa"` and the haystack `"cbaaaaab"`
219213
/// might produce the stream
220214
/// `[Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]`
221215
fn next(&mut self) -> SearchStep;
222216

223-
/// Finds the next `Match` result. See `next()`
217+
/// Finds the next [`Match`][SearchStep::Match] result. See [`next()`][Searcher::next].
224218
///
225-
/// Unlike next(), there is no guarantee that the returned ranges
226-
/// of this and next_reject will overlap. This will return (start_match, end_match),
227-
/// where start_match is the index of where the match begins, and end_match is
228-
/// the index after the end of the match.
219+
/// Unlike [`next()`][Searcher::next], there is no guarantee that the returned ranges
220+
/// of this and [`next_reject`][Searcher::next_reject] will overlap. This will return
221+
/// `(start_match, end_match)`, where start_match is the index of where
222+
/// the match begins, and end_match is the index after the end of the match.
229223
#[inline]
230224
fn next_match(&mut self) -> Option<(usize, usize)> {
231225
loop {
@@ -237,10 +231,11 @@ pub unsafe trait Searcher<'a> {
237231
}
238232
}
239233

240-
/// Finds the next `Reject` result. See `next()` and `next_match()`
234+
/// Finds the next [`Reject`][SearchStep::Reject] result. See [`next()`][Searcher::next]
235+
/// and [`next_match()`][Searcher::next_match].
241236
///
242-
/// Unlike next(), there is no guarantee that the returned ranges
243-
/// of this and next_match will overlap.
237+
/// Unlike [`next()`][Searcher::next], there is no guarantee that the returned ranges
238+
/// of this and [`next_match`][Searcher::next_match] will overlap.
244239
#[inline]
245240
fn next_reject(&mut self) -> Option<(usize, usize)> {
246241
loop {
@@ -258,37 +253,41 @@ pub unsafe trait Searcher<'a> {
258253
/// This trait provides methods for searching for non-overlapping
259254
/// matches of a pattern starting from the back (right) of a string.
260255
///
261-
/// It will be implemented by associated `Searcher`
262-
/// types of the `Pattern` trait if the pattern supports searching
256+
/// It will be implemented by associated [`Searcher`]
257+
/// types of the [`Pattern`] trait if the pattern supports searching
263258
/// for it from the back.
264259
///
265260
/// The index ranges returned by this trait are not required
266261
/// to exactly match those of the forward search in reverse.
267262
///
268263
/// For the reason why this trait is marked unsafe, see them
269-
/// parent trait `Searcher`.
264+
/// parent trait [`Searcher`].
270265
pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
271266
/// Performs the next search step starting from the back.
272267
///
273-
/// - Returns `Match(a, b)` if `haystack[a..b]` matches the pattern.
274-
/// - Returns `Reject(a, b)` if `haystack[a..b]` can not match the
275-
/// pattern, even partially.
276-
/// - Returns `Done` if every byte of the haystack has been visited
268+
/// - Returns [`Match(a, b)`][SearchStep::Match] if `haystack[a..b]`
269+
/// matches the pattern.
270+
/// - Returns [`Reject(a, b)`][SearchStep::Reject] if `haystack[a..b]`
271+
/// can not match the pattern, even partially.
272+
/// - Returns [`Done`][SearchStep::Done] if every byte of the haystack
273+
/// has been visited
277274
///
278-
/// The stream of `Match` and `Reject` values up to a `Done`
275+
/// The stream of [`Match`][SearchStep::Match] and
276+
/// [`Reject`][SearchStep::Reject] values up to a [`Done`][SearchStep::Done]
279277
/// will contain index ranges that are adjacent, non-overlapping,
280278
/// covering the whole haystack, and laying on utf8 boundaries.
281279
///
282-
/// A `Match` result needs to contain the whole matched pattern,
283-
/// however `Reject` results may be split up into arbitrary
284-
/// many adjacent fragments. Both ranges may have zero length.
280+
/// A [`Match`][SearchStep::Match] result needs to contain the whole matched
281+
/// pattern, however [`Reject`][SearchStep::Reject] results may be split up
282+
/// into arbitrary many adjacent fragments. Both ranges may have zero length.
285283
///
286284
/// As an example, the pattern `"aaa"` and the haystack `"cbaaaaab"`
287285
/// might produce the stream
288-
/// `[Reject(7, 8), Match(4, 7), Reject(1, 4), Reject(0, 1)]`
286+
/// `[Reject(7, 8), Match(4, 7), Reject(1, 4), Reject(0, 1)]`.
289287
fn next_back(&mut self) -> SearchStep;
290288

291-
/// Finds the next `Match` result. See `next_back()`
289+
/// Finds the next [`Match`][SearchStep::Match] result.
290+
/// See [`next_back()`][ReverseSearcher::next_back].
292291
#[inline]
293292
fn next_match_back(&mut self) -> Option<(usize, usize)> {
294293
loop {
@@ -300,7 +299,8 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
300299
}
301300
}
302301

303-
/// Finds the next `Reject` result. See `next_back()`
302+
/// Finds the next [`Reject`][SearchStep::Reject] result.
303+
/// See [`next_back()`][ReverseSearcher::next_back].
304304
#[inline]
305305
fn next_reject_back(&mut self) -> Option<(usize, usize)> {
306306
loop {
@@ -313,10 +313,10 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
313313
}
314314
}
315315

316-
/// A marker trait to express that a `ReverseSearcher`
317-
/// can be used for a `DoubleEndedIterator` implementation.
316+
/// A marker trait to express that a [`ReverseSearcher`]
317+
/// can be used for a [`DoubleEndedIterator`] implementation.
318318
///
319-
/// For this, the impl of `Searcher` and `ReverseSearcher` need
319+
/// For this, the impl of [`Searcher`] and [`ReverseSearcher`] need
320320
/// to follow these conditions:
321321
///
322322
/// - All results of `next()` need to be identical
@@ -328,7 +328,7 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
328328
/// # Examples
329329
///
330330
/// `char::Searcher` is a `DoubleEndedSearcher` because searching for a
331-
/// `char` only requires looking at one at a time, which behaves the same
331+
/// [`char`] only requires looking at one at a time, which behaves the same
332332
/// from both ends.
333333
///
334334
/// `(&str)::Searcher` is not a `DoubleEndedSearcher` because
@@ -355,13 +355,13 @@ pub struct CharSearcher<'a> {
355355
/// `finger_back` is the current byte index of the reverse search.
356356
/// Imagine that it exists after the byte at its index, i.e.
357357
/// haystack[finger_back - 1] is the last byte of the slice we must inspect during
358-
/// forward searching (and thus the first byte to be inspected when calling next_back())
358+
/// forward searching (and thus the first byte to be inspected when calling next_back()).
359359
finger_back: usize,
360360
/// The character being searched for
361361
needle: char,
362362

363363
// safety invariant: `utf8_size` must be less than 5
364-
/// The number of bytes `needle` takes up when encoded in utf8
364+
/// The number of bytes `needle` takes up when encoded in utf8.
365365
utf8_size: usize,
366366
/// A utf8 encoded copy of the `needle`
367367
utf8_encoded: [u8; 4],
@@ -521,7 +521,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
521521

522522
impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {}
523523

524-
/// Searches for chars that are equal to a given `char`.
524+
/// Searches for chars that are equal to a given [`char`].
525525
///
526526
/// # Examples
527527
///
@@ -772,7 +772,7 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
772772

773773
impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
774774

775-
/// Searches for chars that are equal to any of the chars in the slice.
775+
/// Searches for chars that are equal to any of the [`char`]s in the slice.
776776
///
777777
/// # Examples
778778
///
@@ -821,7 +821,7 @@ where
821821

822822
impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F> where F: FnMut(char) -> bool {}
823823

824-
/// Searches for chars that match the given predicate.
824+
/// Searches for [`char`]s that match the given predicate.
825825
///
826826
/// # Examples
827827
///

0 commit comments

Comments
 (0)