Created
January 7, 2019 23:01
-
-
Save frol/21506b2bc079f0d19bd868add8867679 to your computer and use it in GitHub Desktop.
This is just an abuse of Not operator to get a shortcut syntax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #[derive(Debug, Clone)] | |
| struct AutoRc<T>(pub std::rc::Rc<T>); | |
| impl<T: Clone> std::ops::Not for &AutoRc<T> { | |
| type Output = AutoRc<T>; | |
| fn not(self) -> Self::Output { | |
| AutoRc(self.0.clone()) | |
| } | |
| } | |
| fn qq1(a: AutoRc<i32>) { | |
| println!("{:?}", a); | |
| } | |
| fn main() { | |
| let a = AutoRc(std::rc::Rc::new(1)); | |
| qq1(!&a); | |
| qq1(!&a); | |
| println!("{:?}", a); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment