1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
pub fn count(text: String, substring: &str) -> usize {
    text.matches(substring).count() as usize
}


#[cfg(test)]
mod tests {
    use super::count;

    #[test]
    fn test_count() {
        let text = String::from("Hello World");
        let substring = "l";

        assert_eq!(count(text, substring), 3);
    }
}