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 touches a different field. The proposal is intentionally minimal (MVP): it adds explicit field-set annotations to method signatures and borrow expressions, integrates cleanly into the borrow checker by splitting a single loan into per-field loans, and has no runtime cost. Limitations include restricted use with private fields and no inference (yet). The author argues this is implementable now and should be shipped as a lang experiment, with inference and abstract fields as future extensions.
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: