A proposal for 'view types' in Rust that would allow methods to declare which struct fields they access via a new syntax like `&mut self {statistics}`. This solves a common borrow checker limitation where calling a helper method inside a loop that already borrows one field of self causes a conflict, even when the method only

14m read timeFrom smallcultfollowing.com
Post cover image
Table of contents
Example: MessageProcessorWhat’s needed: a way for the borrow checker to know what fields a method may accessView types extend struct types with a list of fieldsView types respect privacyView types can be named on self arguments and elsewhereExplicit view-limited borrowsWe automatically introduce view borrows in an auto-refThe borrow checker would respect viewsExample: putting it all togetherAt runtime, this is still just a pointerFrequently asked questionsConclusion: this is a good MVP, let’s ship it!

Sort: