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.
Activity
oli-obk commentedon Apr 1, 2016
dupe of #1215
steveklabnik commentedon Apr 1, 2016
Yes, closing as a duplicate. Thanks!
jFransham commentedon Apr 2, 2016
I asked on IRC if that existed and I couldn't find it when I searched for "disjoint". Is there a better way to find duplicates?