1 pub fn first_word(s: &str) -> &str {
2 for (i, &item) in s.as_bytes().iter().enumerate() {
11 pub fn second_word(s: &str) -> Option<&str> {
12 for (i, &item) in s.as_bytes().iter().enumerate() {
14 return Some(first_word(&s[(i + 1)..]));
26 fn test_first_word() {
27 assert_eq!(first_word(""), "");
28 assert_eq!(first_word("one"), "one");
29 assert_eq!(first_word("one two"), "one");
31 assert_eq!(first_word(&String::from("one two")), "one");
35 fn test_second_word() {
36 assert_eq!(second_word(""), None);
37 assert_eq!(second_word("one"), None);
38 assert_eq!(second_word("one two"), Some("two"));
39 assert_eq!(second_word("one two three"), Some("two"));
41 assert_eq!(second_word(&String::from("one two three")), Some("two"));