Borrow 1.0: zero-overhead Partial Borrows, borrows of selected fields only, like `&<mut field1, mut field2>MyStruct`.
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:
- Rust Internals "Notes on partial borrow".
- The Rustonomicon "Splitting Borrows".
- Niko Matsakis Blog Post "After NLL: Interprocedural conflicts".
- Afternoon Rusting "Multiple Mutable References".
- Partial borrows Rust RFC.
- HackMD "My thoughts on (and need for) partial borrows".
- Dozens of threads on different platforms.
⭐ 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!