Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 4.64 KB | None | 0 0
  1. #[macro_export]                                                                                                                                                                                                                              
  2. macro_rules! create_set_flag_method {                                                                                                                                                                                                        
  3.     ($method:ident, $flag:expr, $platforms:expr) => (                                                                                                                                                                                        
  4.         #[cfg(platforms)]                                                                                                                                                                                                                    
  5.         pub fn $method(enabled: bool) -> Result<(), ()> {                                                                                                                                                                                    
  6.             if enabled {                                                                                                                                                                                                                      
  7.                 self.flags = self.flags | flag;                                                                                                                                                                                              
  8.             } else {                                                                                                                                                                                                                          
  9.                 self.flags = self.flags & !flag;                                                                                                                                                                                              
  10.             }                                                                                                                                                                                                                                
  11.             Ok(())                                                                                                                                                                                                                            
  12.         }                                                                                                                                                                                                                                    
  13.         #[cfg(not(platforms))]                                                                                                                                                                                                                
  14.         pub fn $method(_enabled: bool) -> Result<(), ()> {                                                                                                                                                                                    
  15.             Err(())                                                                                                                                                                                                                          
  16.         }                                                                                                                                                                                                                                    
  17.     )                                                                                                                                                                                                                                        
  18. }
  19.  
  20.  
  21. // ...
  22.  
  23.         create_set_flag_method!(
  24.             set_nonblocking,
  25.             MSG_DONTWAIT,
  26.             any(target_os = "freebsd", target_os = "linux")
  27.         );
  28.  
  29.  
  30. // make fails with following error:
  31.  
  32.  
  33. error[E0428]: a value named `set_nonblocking` has already been defined in this module
  34.    --> src/transport.rs:217:9
  35.     |
  36. 217 |            pub fn $method(_enabled: bool) -> Result<(), ()> {
  37.     |   _________-
  38.     |  |_________|
  39.     | ||
  40. 218 | ||             Err(())
  41. 219 | ||         }
  42.     | ||         -
  43.     | ||_________|
  44.     | |__________`set_nonblocking` already defined
  45.     |            previous definition of `set_nonblocking` here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement