You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Currently the getter/setter pattern is problematic in Rust because the borrow checker cannot be sure that a given function only accesses a certain set of fields, which means that getter functions are strictly less useful than field accesses. I propose a syntax somehow similar to this:
structBar;structFoo{a:Bar,b:Bar,}implFoo{fna_mut(&mutself) -> &mutBar{&mutself.a}fnb_mut(&mutself) -> &mutBar{&mutself.b}fna_mut_2(&mutSelf{ a }) -> &mutBar{&mut a
}fnb_mut_2(&mutSelf{ b }) -> &mutBar{&mut b
}}fnmain(){// This currently does not work in Rust{letmut foo = Foo{a:Bar,b:Bar};let a = foo.a_mut();let b = foo.b_mut();}// This would work, with disjointness annotations{letmut foo = Foo{a:Bar,b:Bar};let a = foo.a_mut_2();let b = foo.b_mut_2();}}
This would also probably work well with the fields in traits proposal.
The text was updated successfully, but these errors were encountered:
Currently the getter/setter pattern is problematic in Rust because the borrow checker cannot be sure that a given function only accesses a certain set of fields, which means that getter functions are strictly less useful than field accesses. I propose a syntax somehow similar to this:
This would also probably work well with the fields in traits proposal.
The text was updated successfully, but these errors were encountered: