Question about reborrowing?
โ Rust ๐ 2026-01-29 ๐ค surdeus ๐๏ธ 9Am 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
๐ท๏ธ Rust_feed