I found it confusing that &(*&a)
and &{*&a}
behave differently.
To be detailed, the following code failed to compile:
struct CanNotCopy;
fn main(){
let a = CanNotCopy;
&{*&a};
let c = a;
}
And the following code compiled:
struct CanNotCopy;
fn main(){
let a = CanNotCopy;
&(*&a); // or &*&a;
let c = a;
}
What is the semantical difference between the above codes?
Which are language constructs that lead to the transfer of ownership, precisely?
You can remove existing occupier/s if the remaining occupier/s qualify to retain the rental flat under our prevailing policy. You can submit your request by approaching the HDB Branch.
If a joint-owner has passed away, his or her share or interest in the flat will be transferred to the remaining owners, who will have to lodge a Notice of Death with the Singapore Land Authority (SLA).
Whether a private property owner can inherit an HDB or not depends on when the original owner purchased the HDB flat. If the HDB flat was purchased before 30th August 2010, then you can keep both the properties – the private residential property and the inherited HDB.
Flat owners can print the HDB's confirmation letter, after logging in with Singpass at http://www.hdb.gov.sg/rentingout, via Renting Out of Bedroom(s) > Enquiry on Tenants. Alternatively, flat owners may use our 'Enquiry on Authorised Tenants' e-Service to assure their tenants that they have been registered with HDB.
By using {}
you are moving a
into a new scope, which then you play referencing and dereferencing. It can also be simplified to:
struct CanNotCopy;
fn main(){
let a = CanNotCopy;
{a};
let c = a;
}
You would be getting the same problem, now lets move to the other problem. Imagine you have a reference before the scope:
struct CanNotCopy;
fn main(){
let a = CanNotCopy;
let aa = &a;
{aa};
let c = a;
}
This works, because we just move the reference and not the original object itself.
How about the operations with *
and &
then:
struct CanNotCopy;
fn main(){
let a = CanNotCopy;
let aa = &a;
&{*aa};
let c = a;
}
We got to a cannot move out of *aa which is behind a shared reference
because of the same reasons above showed.
We do not have that error with ()
because we are working within the same scope hence nothing is really moving there.
EDIT (taken from comments), Some related questions:
What does “&*” do in Rust
What's the difference between &mut unsafe { } and unsafe { &mut }?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With