-
Notifications
You must be signed in to change notification settings - Fork 124
Closed
Description
TODO: Expand based on the following ideas:
- We can't implement
is_bit_valid
forUnsafeCell
because it requires reading from memory which is behind anUnsafeCell
. There's no way to do this without raw pointers, and even with raw pointers, we don't know how other code is accessing the same memory (e.g., it might be using atomics, which would cause UB if we accessed it via non-atomic accesses).- We should modify
is_bit_valid
to have awhere Self: NoCell
bound.
- We should modify
- We still want to be able to use
TryFromBytes
forUnsafeCell
. - We should add a separate method:
TryFromBytes::is_bit_valid_mut
. Likeis_bit_valid
, but itsPtr
argument hasinvariant::Exclusive
.- We can call this method from
try_read_from
- We can call this method from
- Inside of the
is_bit_valid_mut
impl forUnsafeCell
, we do the following:- Cast to
UnsafeCell<Unalign<MaybeValid<T>>>
(see below for discussion ofMaybeValid
) - Use
Ptr::as_mut
to get a&mut UnsafeCell<Unalign<MaybeValid<T>>>
- Use
UnsafeCell::get_mut
to get a&mut Unalign<MaybeValid<T>>
- Delegate to
<Unalign<MaybeValid<T>> as TryFromBytes>::is_bit_valid_mut
- Cast to
- Add
MaybeValid<T>
, which is justMaybeUninit<T>
but with the "as initialized" invariant.
Metadata
Metadata
Assignees
Labels
No labels