Question Details

No question body available.

Tags

rust scope lifetime entity-component-system refcell

Answers (1)

Accepted Answer Available
Accepted Answer
July 5, 2025 Score: 3 Rep: 904 Quality: High Completeness: 80%

The reborrow trick from kmdreko was almost right, you just have to reborrow both data1 and data2: (playground)

use std::cell::RefCell;

trait ScopedFetch { type Result); fn reborrowresult) -> Self::Result ScopedFetch for &RefCell { type Result) { let data = self.borrow(); func(&data); } fn reborrowresult) -> Self::Result = (SF1::Result);

fn fetch(&self, func: F) where F: for) { let (sf1, sf2) = self; sf1.fetch(|data1| { sf2.fetch(|data2| { let data1 = SF1::reborrowresult(data1); let data2 = SF2::reborrowresult(data2); func((data1, data2)); }); }); } fn reborrow_result) -> Self::Result