Question about reborrowing?

โš“ Rust    ๐Ÿ“… 2026-01-29    ๐Ÿ‘ค surdeus    ๐Ÿ‘๏ธ 9      

surdeus

Warning

This post was published 33 days ago. The information described in this article may have changed.

Info

This post is auto-generated from RSS feed The Rust Programming Language Forum - Latest topics. Source: Question about reborrowing?

Am I right that a reborrow happens when I pass a &mut T through to another function?

fn f1(t: &mut Thing) { ... }
fn f2(t: &mut Thing) {
    ...
    f1(t); // here?
}

But itโ€™s not really possible to package up a few mutable references and pass them together and have them reborrowed? Something like this:

struct Context<'a, 'b> {
    thing: &mut 'a Thing,
    other: &mut 'b Other,
}
fn f1(ctx: Context) { ... }
fn f2(t: &mut Thing) {
    let mut other_thing: Other = ...
    let ctx = Contex {
        thing: t,
        other: &mut other_thing
    };
    f1(ctx);
    t.x = 123;
    ...
}

4 posts - 4 participants

Read full topic

๐Ÿท๏ธ Rust_feed