partial_ref - Type checked partial references.

crates.io docs.rs

This crate provides type checked partial references for rust. Type checked partial references are one solution to solve interprocedural borrowing conflicts.

Soundness Issues

Previous versions had a potential soundness issue regarding internal address computations. This was not clear at the time I wrote the first version. Later it became clear, but there was no viable alternative, so I added a warning to this readme. Now with [addr_of] and [addr_of_mut] being stabilized since Rust 1.51, I updated the implementation to avoid this issue.

Deprecation

I wrote this library for its use in [Varisat]. After making extensive use of this, I am not convinced that overall this is a good approach to solve interprocedural borrowing conflict issues. In particular I think the implementation is way too complex for the functionality it provides.

I am currently working on a new version of this library that implements the same essential idea using a slightly simpler API and a much simpler implementation. In general I would recommend trying alternative workarounds to avoid interprocedural borrowing conflicts, but if you come to the conclusion that partial references are the best solution for your use case, my advice would be to wait for the new version of this library to be released.

Example

```rust use partial_ref::*;

part!(pub Neighbors: Vec>); part!(pub Colors: Vec); part!(pub Weights: Vec);

[derive(PartialRefTarget, Default)]

pub struct Graph { #[part(Neighbors)] pub neighbors: Vec>, #[part(Colors)] pub colors: Vec, #[part(Weights)] pub weights: 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);
}

} ```

Documentation

License

The partial_ref source code is licensed under either of

at your option.

Contribution

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.