#reference #partial #part #ref #neighbor #borrowing #first

deprecated partial_ref

Type checked partial references

9 releases

0.3.3 Jul 17, 2021
0.3.2 Sep 9, 2020
0.3.1 Apr 20, 2019
0.2.0 Mar 22, 2019
0.1.0 Dec 24, 2018

#20 in #neighbor

Download history 4920/week @ 2024-01-05 3525/week @ 2024-01-12 2779/week @ 2024-01-19 3518/week @ 2024-01-26 3699/week @ 2024-02-02 3475/week @ 2024-02-09 4257/week @ 2024-02-16 3240/week @ 2024-02-23 4788/week @ 2024-03-01 3965/week @ 2024-03-08 4154/week @ 2024-03-15 4508/week @ 2024-03-22 4247/week @ 2024-03-29 4382/week @ 2024-04-05 4799/week @ 2024-04-12 3760/week @ 2024-04-19

17,944 downloads per month
Used in 19 crates (2 directly)


663 lines

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.


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.


use partial_ref::*;

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

#[derive(PartialRefTarget, Default)]
pub struct Graph {
    pub neighbors: Vec<Vec<usize>>,
    pub colors: Vec<usize>,
    pub weights: Vec<f32>,

let mut g = Graph::default();
let mut g_ref = g.into_partial_ref_mut();

g_ref.part_mut(Colors).extend(&[0, 1, 0]);
g_ref.part_mut(Weights).extend(&[0.25, 0.5, 0.75]);

g_ref.part_mut(Neighbors).push(vec![1, 2]);
g_ref.part_mut(Neighbors).push(vec![0, 2]);
g_ref.part_mut(Neighbors).push(vec![0, 1]);

pub fn add_color_to_weight(
    mut g: partial!(Graph, mut Weights, Colors),
    index: usize,
) {
    g.part_mut(Weights)[index] += g.part(Colors)[index] as f32;

let (neighbors, mut g_ref) = g_ref.split_part_mut(Neighbors);
let (colors, mut g_ref) = g_ref.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.


~34K SLoC