Advertisement
cwchen

[Rust] function with parameters and return value

Aug 23rd, 2017
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.35 KB | None | 0 0
  1. fn capitalize(s: &str) -> String {
  2.     let mut c = s.chars();
  3.     match c.next() {
  4.         None => String::new(),
  5.         Some(f) => f.to_uppercase().collect::<String>() + c.as_str(),
  6.     }
  7. }
  8.  
  9. fn main() {
  10.     assert_eq!(capitalize("apple"), "Apple");
  11.     assert_eq!(capitalize("banana"), "Banana");
  12.     assert_eq!(capitalize("orange"), "Orange");
  13. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement