Add examples to Pattern docs
This commit is contained in:
parent
cbe96b04ad
commit
7a22cf6415
2 changed files with 32 additions and 0 deletions
|
@ -1828,6 +1828,12 @@ impl<'a> Extend<Cow<'a, str>> for String {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A convenience impl that delegates to the impl for `&str`.
|
/// A convenience impl that delegates to the impl for `&str`.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// assert_eq!(String::from("Hello world").find("world"), Some(6));
|
||||||
|
/// ```
|
||||||
#[unstable(
|
#[unstable(
|
||||||
feature = "pattern",
|
feature = "pattern",
|
||||||
reason = "API not fully fleshed out and ready to be stabilized",
|
reason = "API not fully fleshed out and ready to be stabilized",
|
||||||
|
|
|
@ -452,6 +452,12 @@ unsafe impl<'a> ReverseSearcher<'a> for CharSearcher<'a> {
|
||||||
impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {}
|
impl<'a> DoubleEndedSearcher<'a> for CharSearcher<'a> {}
|
||||||
|
|
||||||
/// Searches for chars that are equal to a given `char`.
|
/// Searches for chars that are equal to a given `char`.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// assert_eq!("Hello world".find('o'), Some(4));
|
||||||
|
/// ```
|
||||||
impl<'a> Pattern<'a> for char {
|
impl<'a> Pattern<'a> for char {
|
||||||
type Searcher = CharSearcher<'a>;
|
type Searcher = CharSearcher<'a>;
|
||||||
|
|
||||||
|
@ -697,6 +703,13 @@ unsafe impl<'a, 'b> ReverseSearcher<'a> for CharSliceSearcher<'a, 'b> {
|
||||||
impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
|
impl<'a, 'b> DoubleEndedSearcher<'a> for CharSliceSearcher<'a, 'b> {}
|
||||||
|
|
||||||
/// Searches for chars that are equal to any of the chars in the array.
|
/// Searches for chars that are equal to any of the chars in the array.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// assert_eq!("Hello world".find(&['l', 'l'] as &[_]), Some(2));
|
||||||
|
/// assert_eq!("Hello world".find(&['l', 'l'][..]), Some(2));
|
||||||
|
/// ```
|
||||||
impl<'a, 'b> Pattern<'a> for &'b [char] {
|
impl<'a, 'b> Pattern<'a> for &'b [char] {
|
||||||
pattern_methods!(CharSliceSearcher<'a, 'b>, MultiCharEqPattern, CharSliceSearcher);
|
pattern_methods!(CharSliceSearcher<'a, 'b>, MultiCharEqPattern, CharSliceSearcher);
|
||||||
}
|
}
|
||||||
|
@ -739,6 +752,13 @@ where
|
||||||
impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F> where F: FnMut(char) -> bool {}
|
impl<'a, F> DoubleEndedSearcher<'a> for CharPredicateSearcher<'a, F> where F: FnMut(char) -> bool {}
|
||||||
|
|
||||||
/// Searches for chars that match the given predicate.
|
/// Searches for chars that match the given predicate.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// assert_eq!("Hello world".find(char::is_uppercase), Some(0));
|
||||||
|
/// assert_eq!("Hello world".find(|c| "aeiou".contains(c)), Some(1));
|
||||||
|
/// ```
|
||||||
impl<'a, F> Pattern<'a> for F
|
impl<'a, F> Pattern<'a> for F
|
||||||
where
|
where
|
||||||
F: FnMut(char) -> bool,
|
F: FnMut(char) -> bool,
|
||||||
|
@ -763,6 +783,12 @@ impl<'a, 'b, 'c> Pattern<'a> for &'c &'b str {
|
||||||
///
|
///
|
||||||
/// Will handle the pattern `""` as returning empty matches at each character
|
/// Will handle the pattern `""` as returning empty matches at each character
|
||||||
/// boundary.
|
/// boundary.
|
||||||
|
///
|
||||||
|
/// # Examples
|
||||||
|
///
|
||||||
|
/// ```
|
||||||
|
/// assert_eq!("Hello world".find("world"), Some(6));
|
||||||
|
/// ```
|
||||||
impl<'a, 'b> Pattern<'a> for &'b str {
|
impl<'a, 'b> Pattern<'a> for &'b str {
|
||||||
type Searcher = StrSearcher<'a, 'b>;
|
type Searcher = StrSearcher<'a, 'b>;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue