https://github.com/mpdn/disjoint-borrow
Disjoint borrow of slices in Rust
https://github.com/mpdn/disjoint-borrow
Last synced: about 1 year ago
JSON representation
Disjoint borrow of slices in Rust
- Host: GitHub
- URL: https://github.com/mpdn/disjoint-borrow
- Owner: mpdn
- License: mit
- Created: 2019-09-01T19:24:46.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-09-01T20:23:23.000Z (almost 7 years ago)
- Last Synced: 2025-05-08T01:44:30.894Z (about 1 year ago)
- Language: Rust
- Size: 9.77 KB
- Stars: 11
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://travis-ci.org/noctune/disjoint-borrow)
# disjoint-borrow
Disjoint borrows of slices.
Provides the [`DisjointSlice`](struct.DisjointSlice.html) type, allowing disjoint borrows over
slices by adding runtime checks. Immutable borrows are allowed to intersect with other immutable
borrows, while mutable borrows may not intersect with any borrows.
Borrow tracking is implemented as type-level list. This has the advantage that no allocation is
necessary, but also limits the number of disjoint borrows to a compile-time constant.
No-std compatible.
## Example
```rust
use disjoint_borrow::DisjointSlice;
let mut array = [1, 2, 3, 4, 5];
let mut ds = DisjointSlice::new(&mut array);
let (mut ds, mut a) = ds.get_mut(0..2);
let (_, mut b) = ds.get_mut(3..5);
a[0] *= -1;
b[1] *= -1;
assert_eq!(a, &[-1, 2]);
assert_eq!(b, &[4, -5]);
```
License: MIT