hat_splitter/
split.rs

1pub trait Splitter {
2    fn split<'a>(&self, input: &'a str) -> Vec<&'a str>;
3}
4
5pub struct WhitespaceSplitter;
6
7impl Splitter for WhitespaceSplitter {
8    fn split<'a>(&self, input: &'a str) -> Vec<&'a str> {
9        input.split_whitespace().collect()
10    }
11}
12
13#[cfg(test)]
14mod tests {
15    use super::*;
16
17    #[test]
18    fn it_works() {
19        let splitter = WhitespaceSplitter;
20        let input = "Hello, world! This is a test.";
21        let result = splitter.split(input);
22        assert_eq!(result, vec!["Hello,", "world!", "This", "is", "a", "test."]);
23    }
24}