@@ -45,13 +45,13 @@ use crate::slice::memchr;
4545/// A string pattern.
4646///
4747/// A `Pattern<'a>` expresses that the implementing type
48- /// 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] .
4949///
5050/// For example, both `'a'` and `"aa"` are patterns that
5151/// would match at index `1` in the string `"baaaab"`.
5252///
5353/// The trait itself acts as a builder for an associated
54- /// `Searcher` type, which does the actual work of finding
54+ /// [ `Searcher`] type, which does the actual work of finding
5555/// occurrences of the pattern in a string.
5656///
5757/// Depending on the type of the pattern, the behaviour of methods like
@@ -156,7 +156,7 @@ pub trait Pattern<'a>: Sized {
156156
157157// Searcher
158158
159- /// Result of calling `Searcher::next()` or `ReverseSearcher::next_back()`.
159+ /// Result of calling [ `Searcher::next()`] or [ `ReverseSearcher::next_back()`] .
160160#[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
161161pub enum SearchStep {
162162 /// Expresses that a match of the pattern has been found at
@@ -179,44 +179,47 @@ pub enum SearchStep {
179179/// matches of a pattern starting from the front (left) of a string.
180180///
181181/// It will be implemented by associated `Searcher`
182- /// types of the `Pattern` trait.
182+ /// types of the [ `Pattern`] trait.
183183///
184184/// The trait is marked unsafe because the indices returned by the
185- /// `next()` methods are required to lie on valid utf8 boundaries in
186- /// 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
187187/// slice the haystack without additional runtime checks.
188188pub unsafe trait Searcher < ' a > {
189189 /// Getter for the underlying string to be searched in
190190 ///
191- /// Will always return the same `&str`
191+ /// Will always return the same [ `&str`][str].
192192 fn haystack ( & self ) -> & ' a str ;
193193
194194 /// Performs the next search step starting from the front.
195195 ///
196- /// - Returns `Match(a, b)` if `haystack[a..b]` matches the pattern.
197- /// - Returns `Reject(a, b)` if `haystack[a..b]` can not match the
198- /// pattern, even partially.
199- /// - 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.
200202 ///
201- /// 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]
202205 /// will contain index ranges that are adjacent, non-overlapping,
203206 /// covering the whole haystack, and laying on utf8 boundaries.
204207 ///
205- /// A `Match` result needs to contain the whole matched pattern,
206- /// however `Reject` results may be split up into arbitrary
207- /// 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.
208211 ///
209212 /// As an example, the pattern `"aaa"` and the haystack `"cbaaaaab"`
210213 /// might produce the stream
211214 /// `[Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]`
212215 fn next ( & mut self ) -> SearchStep ;
213216
214- /// Finds the next `Match` result. See `next()`
217+ /// Finds the next [ `Match`][SearchStep::Match] result. See [ `next()`][Searcher::next].
215218 ///
216- /// Unlike next(), there is no guarantee that the returned ranges
217- /// of this and next_reject will overlap. This will return (start_match, end_match),
218- /// where start_match is the index of where the match begins, and end_match is
219- /// 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.
220223 #[ inline]
221224 fn next_match ( & mut self ) -> Option < ( usize , usize ) > {
222225 loop {
@@ -228,10 +231,11 @@ pub unsafe trait Searcher<'a> {
228231 }
229232 }
230233
231- /// 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].
232236 ///
233- /// Unlike next(), there is no guarantee that the returned ranges
234- /// 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.
235239 #[ inline]
236240 fn next_reject ( & mut self ) -> Option < ( usize , usize ) > {
237241 loop {
@@ -249,37 +253,41 @@ pub unsafe trait Searcher<'a> {
249253/// This trait provides methods for searching for non-overlapping
250254/// matches of a pattern starting from the back (right) of a string.
251255///
252- /// It will be implemented by associated `Searcher`
253- /// 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
254258/// for it from the back.
255259///
256260/// The index ranges returned by this trait are not required
257261/// to exactly match those of the forward search in reverse.
258262///
259263/// For the reason why this trait is marked unsafe, see them
260- /// parent trait `Searcher`.
264+ /// parent trait [ `Searcher`] .
261265pub unsafe trait ReverseSearcher < ' a > : Searcher < ' a > {
262266 /// Performs the next search step starting from the back.
263267 ///
264- /// - Returns `Match(a, b)` if `haystack[a..b]` matches the pattern.
265- /// - Returns `Reject(a, b)` if `haystack[a..b]` can not match the
266- /// pattern, even partially.
267- /// - 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
268274 ///
269- /// 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]
270277 /// will contain index ranges that are adjacent, non-overlapping,
271278 /// covering the whole haystack, and laying on utf8 boundaries.
272279 ///
273- /// A `Match` result needs to contain the whole matched pattern,
274- /// however `Reject` results may be split up into arbitrary
275- /// 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.
276283 ///
277284 /// As an example, the pattern `"aaa"` and the haystack `"cbaaaaab"`
278285 /// might produce the stream
279- /// `[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)]`.
280287 fn next_back ( & mut self ) -> SearchStep ;
281288
282- /// Finds the next `Match` result. See `next_back()`
289+ /// Finds the next [`Match`][SearchStep::Match] result.
290+ /// See [`next_back()`][ReverseSearcher::next_back].
283291 #[ inline]
284292 fn next_match_back ( & mut self ) -> Option < ( usize , usize ) > {
285293 loop {
@@ -291,7 +299,8 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
291299 }
292300 }
293301
294- /// Finds the next `Reject` result. See `next_back()`
302+ /// Finds the next [`Reject`][SearchStep::Reject] result.
303+ /// See [`next_back()`][ReverseSearcher::next_back].
295304 #[ inline]
296305 fn next_reject_back ( & mut self ) -> Option < ( usize , usize ) > {
297306 loop {
@@ -304,10 +313,10 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
304313 }
305314}
306315
307- /// A marker trait to express that a `ReverseSearcher`
308- /// can be used for a `DoubleEndedIterator` implementation.
316+ /// A marker trait to express that a [ `ReverseSearcher`]
317+ /// can be used for a [ `DoubleEndedIterator`] implementation.
309318///
310- /// For this, the impl of `Searcher` and `ReverseSearcher` need
319+ /// For this, the impl of [ `Searcher`] and [ `ReverseSearcher`] need
311320/// to follow these conditions:
312321///
313322/// - All results of `next()` need to be identical
@@ -319,7 +328,7 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
319328/// # Examples
320329///
321330/// `char::Searcher` is a `DoubleEndedSearcher` because searching for a
322- /// `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
323332/// from both ends.
324333///
325334/// `(&str)::Searcher` is not a `DoubleEndedSearcher` because
@@ -346,13 +355,13 @@ pub struct CharSearcher<'a> {
346355 /// `finger_back` is the current byte index of the reverse search.
347356 /// Imagine that it exists after the byte at its index, i.e.
348357 /// haystack[finger_back - 1] is the last byte of the slice we must inspect during
349- /// 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()).
350359 finger_back : usize ,
351360 /// The character being searched for
352361 needle : char ,
353362
354363 // safety invariant: `utf8_size` must be less than 5
355- /// The number of bytes `needle` takes up when encoded in utf8
364+ /// The number of bytes `needle` takes up when encoded in utf8.
356365 utf8_size : usize ,
357366 /// A utf8 encoded copy of the `needle`
358367 utf8_encoded : [ u8 ; 4 ] ,
@@ -512,7 +521,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
512521
513522impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
514523
515- /// Searches for chars that are equal to a given `char`.
524+ /// Searches for chars that are equal to a given [ `char`] .
516525///
517526/// # Examples
518527///
@@ -763,7 +772,7 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
763772
764773impl < ' a , ' b > DoubleEndedSearcher < ' a > for CharSliceSearcher < ' a , ' b > { }
765774
766- /// 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.
767776///
768777/// # Examples
769778///
@@ -812,7 +821,7 @@ where
812821
813822impl < ' a , F > DoubleEndedSearcher < ' a > for CharPredicateSearcher < ' a , F > where F : FnMut ( char ) -> bool { }
814823
815- /// Searches for chars that match the given predicate.
824+ /// Searches for [`char`]s that match the given predicate.
816825///
817826/// # Examples
818827///
0 commit comments