rustlings, I modified iterators2.rs as follows, I cannot build this test.
the build spends a lot of time with no result.
Please help me.
pub fn capitalize_first(input: &str) -> String {
let mut c = input.chars();
let mut result = String::new();
while let Some(first) = c.next() {
let len = result.len();
if len == 0 {
result.push(first.to_ascii_uppercase());
} else {
result.push(first);
}
}
result
}
#[cfg(test)]
mod tests {
use super::*;
// Step 1.
// Tests that verify your `capitalize_first` function implementation
#[test]
fn test_success() {
assert_eq!(capitalize_first("hello"), "Hello");
}
#[test]
fn test_empty() {
assert_eq!(capitalize_first(""), "");
}
// Step 2.
#[test]
fn test_iterate_string_vec() {
let words = vec!["hello", "world"];
let capitalized_words: Vec<_> = words.iter().map(|&word| capitalize_first(word)).collect(); // TODO
assert_eq!(capitalized_words, ["Hello", "World"]);
}
#[test]
fn test_iterate_into_string() {
let words = vec!["hello", " ", "world"];
let mut capitalized_words: String = String::new();
while let Some(&word) = words.iter().next() {
let str = capitalize_first(word);
capitalized_words.push_str(&str);
}
assert_eq!(capitalized_words, "Hello World");
}
}Preformatted text