Advertisement
Guest User

Untitled

a guest
May 20th, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.95 KB | None | 0 0
  1. pub struct Banana {
  2. name: String,
  3. age: u32
  4. }
  5.  
  6. pub fn eat(banana: Banana) {
  7. print!("Ate the {} with after {} years", banana.name, banana.age);
  8. }
  9.  
  10. pub mod rename {
  11. // also U+0000 (NUL) through U+001F (US)
  12. pub const EXFAT_DISALLOWED: &str = "/\\:*?\"<>|";
  13.  
  14. pub fn remove_invalid(s: &mut String) -> () {
  15. let copy = s.clone();
  16. s.clear();
  17. copy.chars()
  18. .filter(|&c| !EXFAT_DISALLOWED.contains(c) )
  19. .for_each(|c| s.push(c))
  20. }
  21. }
  22.  
  23. #[cfg(test)]
  24. mod tests {
  25. use super::rename::remove_invalid;
  26. use super::{Banana, eat};
  27.  
  28. #[test]
  29. fn test_remote_invalid_bad_str_return_without_bad_chars() {
  30. let mut bad = String::from("abba:ba?bb||a");
  31. remove_invalid(&mut bad);
  32. let expected = String::from("abbababba");
  33. assert_eq!(expected, bad);
  34. }
  35.  
  36. #[test]
  37. fn can_eat_banana() {
  38. let b = Banana {name: String::from("Epic banana"), age: 42};
  39.  
  40. eat(b);
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement