This crate provides type checked partial references for rust. Type checked partial references are one solution to solve interprocedural borrowing conflicts.
```rust use partial_ref::*;
part!(pub Neighbors: Vec
pub struct Graph {
#[part = "Neighbors"]
pub neighbors: Vec
let mut g = Graph::default(); let mut gref = g.intopartialrefmut();
gref.partmut(Colors).extend(&[0, 1, 0]); gref.partmut(Weights).extend(&[0.25, 0.5, 0.75]);
gref.partmut(Neighbors).push(vec![1, 2]); gref.partmut(Neighbors).push(vec![0, 2]); gref.partmut(Neighbors).push(vec![0, 1]);
pub fn addcolortoweight( mut g: partial!(Graph, mut Weights, Colors), index: usize, ) { g.partmut(Weights)[index] += g.part(Colors)[index] as f32; }
let (neighbors, mut gref) = gref.splitpartmut(Neighbors); let (colors, mut gref) = gref.split_part(Colors);
for (edges, &color) in neighbors.iter_mut().zip(colors.iter()) { edges.retain(|&neighbor| colors[neighbor] != color);
for &neighbor in edges.iter() {
add_color_to_weight(g_ref.borrow(), neighbor);
}
} ```
The partial_ref source code is licensed under either of
at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in partial_ref by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.