Skip to content

Instantly share code, notes, and snippets.

@frol
Created January 7, 2019 23:01
Show Gist options
  • Select an option

  • Save frol/21506b2bc079f0d19bd868add8867679 to your computer and use it in GitHub Desktop.

Select an option

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
#[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