Capitalize a string in Rust
Rust doesn’t offer a convenient capitalization function on the string type, but there is to_uppercase on the char type. These can be strung together quite elegantly with pattern matching and iterators:
/// Capitalizes the first character in s.
pub fn capitalize(s: &str) -> String {
let mut c = s.chars();
match c.next() {
None => String::new(),
Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
}
}