Is there any update on cross-function partial borrow?

This is a decade old issue and I think it's just one step to being solved, but at its current state it's not ergonomic and looks ugly.

#[derive(Default)]
struct Woo {
    f1: String,
    f2: String,
    f3: String,
}

fn main() {
    let mut t = Woo::default();
    let k = &t.f3;
    // foo(&mut t);
    // Woo::moo(&mut t);
    foo2(&mut t.f1, &mut t.f2);

    dbg!(k);
}

fn foo(Woo { f1, f2, .. }: &mut Woo) {
    // this is rejected
}

fn foo2(f1: &mut String, f2: &mut String) {}

impl Woo {
    pub fn moo(Self { f1, f2, .. }: &mut Self) {
        // rejected
        // also doesn't appear as t.moo
    }
}

http://smallcultfollowing.com/babysteps/blog/2021/11/05/view-types/

There is still no RFC on this issue. It affects code structuring significantly.

1 Like

Are you talking about partial types?

I was thinking about possible solutions comparing my thoughts with existed solutions. Probably, I found out how we can achieve partial borrowing. So, for now I stress test my solution. If all will going fine, I will public it later

Previously I wanted to comment my thoughts here (94 lines of code + text), but when I met commentary on the issue (below), I tried to read all of existing variants and analyze them.

Entry point: https://github.com/rust-lang/rfcs/issues/1215 The best variant for now (in my opinion) is permissions: Permissions by DasLixou · Pull Request #3380 · rust-lang/rfcs · GitHub The next one is in issue above, but I don't like pattern matching at self argument, so I don't really like it

Thank you for remind

Okay, I'm done, you can check my idea out in the next topic:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.