@@ -45,13 +45,13 @@ use crate::slice::memchr;
45
45
/// A string pattern.
46
46
///
47
47
/// 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] .
49
49
///
50
50
/// For example, both `'a'` and `"aa"` are patterns that
51
51
/// would match at index `1` in the string `"baaaab"`.
52
52
///
53
53
/// 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
55
55
/// occurrences of the pattern in a string.
56
56
///
57
57
/// Depending on the type of the pattern, the behaviour of methods like
@@ -156,7 +156,7 @@ pub trait Pattern<'a>: Sized {
156
156
157
157
// Searcher
158
158
159
- /// Result of calling `Searcher::next()` or `ReverseSearcher::next_back()`.
159
+ /// Result of calling [ `Searcher::next()`] or [ `ReverseSearcher::next_back()`] .
160
160
#[ derive( Copy , Clone , Eq , PartialEq , Debug ) ]
161
161
pub enum SearchStep {
162
162
/// Expresses that a match of the pattern has been found at
@@ -179,44 +179,47 @@ pub enum SearchStep {
179
179
/// matches of a pattern starting from the front (left) of a string.
180
180
///
181
181
/// It will be implemented by associated `Searcher`
182
- /// types of the `Pattern` trait.
182
+ /// types of the [ `Pattern`] trait.
183
183
///
184
184
/// 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
187
187
/// slice the haystack without additional runtime checks.
188
188
pub unsafe trait Searcher < ' a > {
189
189
/// Getter for the underlying string to be searched in
190
190
///
191
- /// Will always return the same `&str`
191
+ /// Will always return the same [ `&str`][str].
192
192
fn haystack ( & self ) -> & ' a str ;
193
193
194
194
/// Performs the next search step starting from the front.
195
195
///
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.
200
202
///
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]
202
205
/// will contain index ranges that are adjacent, non-overlapping,
203
206
/// covering the whole haystack, and laying on utf8 boundaries.
204
207
///
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.
208
211
///
209
212
/// As an example, the pattern `"aaa"` and the haystack `"cbaaaaab"`
210
213
/// might produce the stream
211
214
/// `[Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]`
212
215
fn next ( & mut self ) -> SearchStep ;
213
216
214
- /// Finds the next `Match` result. See `next()`
217
+ /// Finds the next [ `Match`][SearchStep::Match] result. See [ `next()`][Searcher::next].
215
218
///
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.
220
223
#[ inline]
221
224
fn next_match ( & mut self ) -> Option < ( usize , usize ) > {
222
225
loop {
@@ -228,10 +231,11 @@ pub unsafe trait Searcher<'a> {
228
231
}
229
232
}
230
233
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].
232
236
///
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.
235
239
#[ inline]
236
240
fn next_reject ( & mut self ) -> Option < ( usize , usize ) > {
237
241
loop {
@@ -249,37 +253,41 @@ pub unsafe trait Searcher<'a> {
249
253
/// This trait provides methods for searching for non-overlapping
250
254
/// matches of a pattern starting from the back (right) of a string.
251
255
///
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
254
258
/// for it from the back.
255
259
///
256
260
/// The index ranges returned by this trait are not required
257
261
/// to exactly match those of the forward search in reverse.
258
262
///
259
263
/// For the reason why this trait is marked unsafe, see them
260
- /// parent trait `Searcher`.
264
+ /// parent trait [ `Searcher`] .
261
265
pub unsafe trait ReverseSearcher < ' a > : Searcher < ' a > {
262
266
/// Performs the next search step starting from the back.
263
267
///
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
268
274
///
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]
270
277
/// will contain index ranges that are adjacent, non-overlapping,
271
278
/// covering the whole haystack, and laying on utf8 boundaries.
272
279
///
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.
276
283
///
277
284
/// As an example, the pattern `"aaa"` and the haystack `"cbaaaaab"`
278
285
/// 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)]`.
280
287
fn next_back ( & mut self ) -> SearchStep ;
281
288
282
- /// Finds the next `Match` result. See `next_back()`
289
+ /// Finds the next [`Match`][SearchStep::Match] result.
290
+ /// See [`next_back()`][ReverseSearcher::next_back].
283
291
#[ inline]
284
292
fn next_match_back ( & mut self ) -> Option < ( usize , usize ) > {
285
293
loop {
@@ -291,7 +299,8 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
291
299
}
292
300
}
293
301
294
- /// Finds the next `Reject` result. See `next_back()`
302
+ /// Finds the next [`Reject`][SearchStep::Reject] result.
303
+ /// See [`next_back()`][ReverseSearcher::next_back].
295
304
#[ inline]
296
305
fn next_reject_back ( & mut self ) -> Option < ( usize , usize ) > {
297
306
loop {
@@ -304,10 +313,10 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
304
313
}
305
314
}
306
315
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.
309
318
///
310
- /// For this, the impl of `Searcher` and `ReverseSearcher` need
319
+ /// For this, the impl of [ `Searcher`] and [ `ReverseSearcher`] need
311
320
/// to follow these conditions:
312
321
///
313
322
/// - All results of `next()` need to be identical
@@ -319,7 +328,7 @@ pub unsafe trait ReverseSearcher<'a>: Searcher<'a> {
319
328
/// # Examples
320
329
///
321
330
/// `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
323
332
/// from both ends.
324
333
///
325
334
/// `(&str)::Searcher` is not a `DoubleEndedSearcher` because
@@ -346,13 +355,13 @@ pub struct CharSearcher<'a> {
346
355
/// `finger_back` is the current byte index of the reverse search.
347
356
/// Imagine that it exists after the byte at its index, i.e.
348
357
/// 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()).
350
359
finger_back : usize ,
351
360
/// The character being searched for
352
361
needle : char ,
353
362
354
363
// 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.
356
365
utf8_size : usize ,
357
366
/// A utf8 encoded copy of the `needle`
358
367
utf8_encoded : [ u8 ; 4 ] ,
@@ -512,7 +521,7 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
512
521
513
522
impl < ' a > DoubleEndedSearcher < ' a > for CharSearcher < ' a > { }
514
523
515
- /// Searches for chars that are equal to a given `char`.
524
+ /// Searches for chars that are equal to a given [ `char`] .
516
525
///
517
526
/// # Examples
518
527
///
@@ -763,7 +772,7 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
763
772
764
773
impl < ' a , ' b > DoubleEndedSearcher < ' a > for CharSliceSearcher < ' a , ' b > { }
765
774
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.
767
776
///
768
777
/// # Examples
769
778
///
@@ -812,7 +821,7 @@ where
812
821
813
822
impl < ' a , F > DoubleEndedSearcher < ' a > for CharPredicateSearcher < ' a , F > where F : FnMut ( char ) -> bool { }
814
823
815
- /// Searches for chars that match the given predicate.
824
+ /// Searches for [`char`]s that match the given predicate.
816
825
///
817
826
/// # Examples
818
827
///
0 commit comments