Advertisement
Guest User

Untitled

a guest
Nov 4th, 2018
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 1.34 KB | None | 0 0
  1. trait IsUpperCase {
  2.     fn is_upper_case(&self) -> bool;
  3. }
  4.  
  5. impl IsUpperCase for &str {
  6.     fn is_upper_case(&self) -> bool {
  7.         let word = self.to_string();
  8.         let mut alphabets = word.chars().filter(|c| c.is_alphabetic());
  9.         return match alphabets {
  10.             a if a.count() == 0 => false,
  11.             _ => alphabets.all(|c| c.is_uppercase())
  12.         }
  13.     }
  14. }
  15.  
  16. // I get the following error:
  17.  
  18. error[E0008]: cannot bind by-move into a pattern guard                                                                                                                          
  19.   --> src/lib.rs:20:13                                                                                                                                                          
  20.    |                                                                                                                                                                            
  21. 20 |             a if a.count() == 0 => false,                                                                                                                                  
  22.    |             ^ moves value into pattern guard
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement