Trait alloc::str::pattern::Searcher[][src]

pub unsafe trait Searcher<'a> {
    fn haystack(&self) -> &'a str;
fn next(&mut self) -> SearchStep; fn next_match(&mut self) -> Option<(usize, usize)> { ... }
fn next_reject(&mut self) -> Option<(usize, usize)> { ... } }
🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

Expand description

字符串模式的搜索者。

trait 提供了从字符串的开头 (left) 开始搜索模式的非重叠匹配的方法。

将通过 Pattern trait 的关联 Searcher 类型实现。

trait 被标记为不安全,因为 next() 方法返回的索引必须位于 haystack 中的有效 utf8 边界上。 这使 trait 的使用者可以对 haystack 进行切片,而无需进行其他运行时检查。

Required methods

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

Getter 查找要在其中搜索的基础字符串

总是返回相同的 &str

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

从头开始执行下一个搜索步骤。

  • 如果 haystack[a..b] 与模式匹配,则返回 Match(a, b)
  • 如果 haystack[a..b] 甚至部分不匹配,则返回 Reject(a, b)
  • 如果已访问 haystack 的每个字节,则返回 Done

直到 DoneMatchReject 值流将包含相邻,不重叠,覆盖整个 haystack 并位于 utf8 边界上的索引范围。

Match 结果需要包含整个匹配的模式,但是 Reject 结果可以分为任意多个相邻的片段。两个范围的长度都可以为零。

例如,模式 "aaa" 和 haystack "cbaaaaab" 可能会产生流 [Reject(0, 1), Reject(1, 2), Match(2, 5), Reject(5, 8)]

Provided methods

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

查找下一个 Match 结果。请参见 next()

next() 不同,不能保证此和 next_reject 的返回范围会重叠。 这将返回 (start_match, end_match),其中 start_match 是匹配开始的索引,end_match 是匹配结束后的索引。

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

查找下一个 Reject 结果。请参见 next()next_match()

next() 不同,不能保证此和 next_match 的返回范围会重叠。

Implementors

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized

🔬 This is a nightly-only experimental API. (pattern #27721)

API not fully fleshed out and ready to be stabilized