Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why would a reference dereference? #55

Open
U007D opened this issue Sep 22, 2016 · 1 comment
Open

Why would a reference dereference? #55

U007D opened this issue Sep 22, 2016 · 1 comment

Comments

@U007D
Copy link
Contributor

U007D commented Sep 22, 2016

In Destructuring, you write

Lets say you want a reference to a variable in a pattern. You can't use & because that matches a reference, rather than creates one (and thus has the effect of dereferencing the object). For example, ...

  1. Do you mean a) "Let's say you want to make a reference to an (ordinary) struct field using a pattern (effectively aliasing the field)", b) "Let's say you want to refer to a reference variable in a struct using a pattern (creating an additional reference to the object referred to by the field)" or c) something else?

  2. Why would "matching a reference" have the effect of dereferencing the object? On the face of it, that is surprising behavior (unless it's to avoid a &&T (in which case I'd still have expected the dereference to yield the expected &T)). Maybe another sentence explaining why the dereference would be helpful?

@U007D U007D changed the title Why would a reference dereference? Docs: Why would a reference dereference? Sep 22, 2016
@U007D U007D changed the title Docs: Why would a reference dereference? Why would a reference dereference? Sep 22, 2016
@nrc
Copy link
Owner

nrc commented Sep 23, 2016

  1. a

  2. There is nothing special about the match, it is about destructuring in patterns, e.g.,

let x = &&42;  // x: &&i32
let y = x; // y: &&i32
let &y = x; // y: &i32
let &&y = x; // y: i32
let ref y = x; // y: &&&i32
let y = &x; // y: &&&i32

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants