Skip to content

Instantly share code, notes, and snippets.

@smallnest
Created September 27, 2019 02:32
Show Gist options
  • Select an option

  • Save smallnest/12edc58dcfa6a5d205484f22bc284f41 to your computer and use it in GitHub Desktop.

Select an option

Save smallnest/12edc58dcfa6a5d205484f22bc284f41 to your computer and use it in GitHub Desktop.
#![feature(core_intrinsics)]

fn main() {
    let x = &false;
    print_type_name_of(x);

    let &x = &false;
    print_type_name_of(x);

    let ref x = &false;
    print_type_name_of(x);
}

fn print_type_name_of<T>(_: T) {
    println!("{}", unsafe { std::intrinsics::type_name::<T>() })
}
&bool
bool
&&bool
@smallnest

Copy link
Copy Markdown
Author

ref on the left side of = is the same as & on the right.

let ref x = 1;
let x = &1;

& on the left side of = is the same as * on the right.

let &y = x;
let y = *x;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment