Borrow 1.0: zero-overhead Partial Borrows, borrows of selected fields only, like `&<mut field1, mut field2>MyStruct`.

363 points wdanilo

https://preview.redd.it/gqg5fed0mv0e1.png?width=1470&format=png&auto=webp&s=36d2e5da44c52018d0c297d83f6589da34a4344b

Zero-overhead "partial borrows" let you borrow selected fields only, like &<mut field1, mut field2>MyStruct. This approach splits structs into non-overlapping sets of mutably borrowed fields, similar to slice::split\_at\_mut but designed specifically for structs.

This crate implements the syntax proposed in Rust Internals "Notes on partial borrow", so you can use it now, before it eventually lands in Rust :)

Partial borrows tackle Rust’s long-standing borrow checker limitations with complex structures. To learn more, read an in-depth problem/solution description in this crate’s README or dive into these resources:

⭐ If you find this crate useful, please spread the word and star it on GitHub!
❤️ Special thanks to this project’s sponsor: Blinkfeed, AI-first email client!

GitHub: https://github.com/wdanilo/borrow
Crates.io: https://crates.io/crates/borrow

Happy borrowing!