/// Find the number of times a `needle` occurs within a string, non-overlapping.
Find the number of times a `needle` occurs within a string, non-overlapping.
Find the number of times a ` needle ` occurs within a string non - overlapping .
pub fn count_matches(x: &str, needle: &str) -> usize {
    if needle.len() == 1 {
        // If we are searching for a 1-byte string, we can provide a much faster path.
        // Since it is one byte, given how UTF8 works, all the resultant slices must be UTF8 too.
        count_matches_byte(x, needle.as_bytes()[0])
    } else {
        x.matches(needle).count()
    }
}
pub fn count_matches ( x : & str , needle : & str ) -> usize { if needle . len ( ) == 1 { // If we are searching for a 1-byte string, we can provide a much faster path. // Since it is one byte, given how UTF8 works, all the resultant slices must be UTF8 too. count_matches_byte ( x , needle . as_bytes ( ) [ 0 ] ) } else { x . matches ( needle ) . count ( ) } }
Find the number of times a `needle` occurs within a string, non-overlapping.
Find the number of times a ` needle ` occurs within a string non - overlapping .
x
&str
needle
&str