The string Pattern API.
The Pattern API provides a generic mechanism for using different pattern types when searching through a string.
For more details, see the traits Pattern
, Searcher
, ReverseSearcher
, and DoubleEndedSearcher
.
Although this API is unstable, it is exposed via stable APIs on the str
type.
Pattern
is implemented in the stable API for &str
, char
, slices of char
, and functions and closures implementing FnMut(char) -> bool
.
let s = "Can you find a needle in a haystack?"; // &str pattern assert_eq!(s.find("you"), Some(4)); // char pattern assert_eq!(s.find('n'), Some(2)); // slice of chars pattern assert_eq!(s.find(&['a', 'e', 'i', 'o', 'u'][..]), Some(1)); // closure pattern assert_eq!(s.find(|c: char| c.is_ascii_punctuation()), Some(35));
CharPredicateSearcher |
Experimental Associated type for |
CharSearcher |
Experimental Associated type for |
CharSliceSearcher |
Experimental Associated type for |
StrSearcher |
Experimental Associated type for |
SearchStep |
Experimental Result of calling |
DoubleEndedSearcher |
Experimental A marker trait to express that a |
Pattern |
Experimental A string pattern. |
ReverseSearcher |
Experimental A reverse searcher for a string pattern. |
Searcher |
Experimental A searcher for a string pattern. |
© 2010 The Rust Project Developers
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
https://doc.rust-lang.org/std/str/pattern/index.html