daily pastebin goal
31%
SHARE
TWEET

Untitled

a guest Mar 26th, 2019 52 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. struct Guard;
  2.  
  3. impl Drop for Guard {
  4.     fn drop(&mut self) {
  5.         println!("Dropped");
  6.     }
  7. }
  8.  
  9. impl Guard {
  10.     pub fn get(&self) -> Option<bool> {
  11.         Some(true)
  12.     }
  13.     pub fn get_none(&self) -> Option<bool> {
  14.         None
  15.     }
  16. }
  17.  
  18. fn main() {
  19.  
  20.     if let Some(_) = Guard.get() {
  21.         println!("Inside IF 1");
  22.     }
  23.     println!("------------");
  24.     if let Some(_) = { Guard.get() } {
  25.         println!("Inside IF 2");
  26.     }
  27.     println!("------------");  
  28.     match { Guard.get() } {
  29.         Some(_) => { println!("Inside Match"); }
  30.         _ => ()
  31.     }
  32.     println!("------------");  
  33.     if Guard.get().is_some() {
  34.         println!("Inside IF 4");
  35.     }
  36.     println!("------------");  
  37.     let x = { Guard.get() };
  38.     if let Some(_) = x {
  39.         println!("Inside IF 5");
  40.     }
  41.     println!("------------");
  42.     if let Some(_) = Guard.get_none() {
  43.         println!("Inside IF 6 in then, never go there");
  44.     } else {
  45.         println!("Inside IF 6 in else");
  46.     }
  47.    
  48. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top