Firstly, I’m not wanting to change the actual approach for these Nor am I asking to remove the existing way
&mut is confusing to those of us who come from somewhere other than c++. I’m wondering if there might be a way to alias this functionality using clearer verbiage?
I’m all for keeping the existing way for users coming from c++ and possibly for special purpose functionality, but for newer users I’m looking for something with better affordances?
Normally I wouldn’t have said anything and just accepted the old way of doing things as an artifact carried up from assembly given it’s 3 letters preceded by an &, but I think one of the goals for RUST is to make an effort to be more ergonomic when a change in syntax improves readability and doesn’t negatively impact compiling and optimization
as an example of my confusion can I get help replicating these examples with existing syntax?
fn main (){
let mut book1 = 1;
let mut book2 = 10;
let mut book3 = 100;
let mut book4 = 1000;
let mut book5 = 10000;
let a = peek book1; // look but don't touch
let b = borrow book2; // change, but only you have it, give it back when done
let c = take book3; // change, only you have it, keep it forever and burn it when done
let d = ~share book4; // dangerous share, d and book4 point to the same object, both can change, both are affected by changes the other makes (the ~ is there as a warning and could be any symbol we decide makes sense)
let e = copy book5; // e gets it's own unique copy of book5, both remain mutable
example_peeker(show book1); // show / peek pair, makes it clear to both sides what's expected without needing to see the other side
example_borrower(loan book2); // loan / borrow pair, makes it clear to both sides what's expected without needing to see the other side
example_taker(give book3); // give / take pair, makes it clear to both sides what's expected without needing to see the other side
example_sharer(~share book4); // ~share / ~share pair, makes it clear to both sides what's expected without needing to see the other side
example_copier(copy book5); // give copier it's own duplicate of book5
}
fn example_peeker(peek book1){} // look but don't touch
fn example_borrower(borrow book2){} // change, but only you have it, give it back when done
fn example_taker(take book3){} // change, only you have it, keep it forever and burn it when done
fn example_sharer(~share book4){} // dangerous share
fn example_copier(copy book5){} // indicate you want your own copy of book5
And if any of these don’t currently exist just comment them out and note it in your reply
NOTE: orginally posted here: https://users.rust-lang.org/t/a-possibly-more-erognomic-syntax-for-borrow/18552
I started this post in a different section because I didn’t know this was here (didn’t show up under the site that came up when searching google for ‘rust language forums’).
If someone can lock the old thread and indicate it’s moved here I’d appreciate it