-
Notifications
You must be signed in to change notification settings - Fork 0
Exclusive Reborrowing Brainstorming
MaulingMonkey edited this page Feb 16, 2024
·
2 revisions
- Ideal "by-value borrow" is
valrow::Valrow<'s, S>
as stands ✔️ - Maybe in scope for
#[derive(valrow::Borrowable)]
-
valrow::ValrowMut<S>
would gains nothing but makinga
andb
individually modifiable, which would be a footgun as the values are destined to be discarded.
Ideal "by-value borrow"s:
struct S_exclusive<'s> { pub a: valrow::Valrow<Arc<u32>>, pub b: &'s mut u32 }
-
struct S_shared <'s> { pub a: valrow::Valrow<Arc<u32>>, pub b: &'s u32 }
- or justValrow<S>
? -
could
Deref
back into&S
Adding a Vec<u32>
would break ABI but encourage:
The ideal "by-value borrow" is something that Deref
s into something other than S
, and can't Deref
back into S
. Into<S>
might be an option. valrow::ValrowMut
/ DerefMut
would encourage modifying a discardable field value, which is lame / to be avoided.
-
struct S_partial { pub b: u32 }
- unusable field discarded -
struct S_copied { pub a: u32, pub b: u32 }
- ❌ freezesa
at possibly stale value (other regular borrows might exist) -
struct S_mixed { pub a: &Cell<u32>, pub b: u32 }
- mix of by-reference and by-value captures -
struct S_padded { _a: Opaque<u32>, pub b: u32 }
- ABI compatible but supressed (only works ifField: Copy
)
struct S { pub a: RefCell<u32>, pub b: u32 }
struct S { pub a: Mutex<u32>, pub b: u32 }
struct S { pub a: RwLock<u32>, pub b: u32 }
- Ideal "by-value borrow"
Deref
s into something other thanS
.-
struct S_partial { pub b: u32 }
- unusable field discarded -
struct S_copied { pub a: u32, pub b: u32 }
- ❌ freezesa
at possibly stale value, panic hazard -
struct S_mixed { pub a: &RefCell<u32>, pub b: u32 }
- mix of by-reference and by-value captures -
struct S_padded { _a: ???, pub b: u32 }
- ❌ can't sanely specify_a
's layout while remainingCopy
.
-
- Anything which may convert
Into<S>
would require acell.borrow().clone()
which is a panic hazard.