Struct lib::unsafe_field::SimultaneousUnsafeAssignment
source · pub struct SimultaneousUnsafeAssignment;Expand description
Assign several UnsafeField ‘simultaneously’.
There might be occasions where we cannot assign multiple fields simultaenously by
reconstructing the struct (though this should be done in most cases). In this case, we
can enforce a slightly lesser form of safety, by upholding invariants “only when the struct”
is read from. This pattern guarantees that we cannot get a &self in between writes to
fields.
unsafe_field::SimultaneousUnsafeAssignment
.with(&mut foo.field_1, 5)
.with(&mut foo.field_2, 10)
.with(&mut foo.field_3, 15)
.set_all();
Safety
- ensure that all invariants are upheld after all assignments are complete
- you must not rely on the ordering of the assignments, that is, the Unit state should be the same no matter the order of the assignments. This should be trivially verifiable, since I’m pretty sure it’s impossible. Just putting it in here in case someon can find a way of doing this.
Implementation Notes
This is possible to implement without storing references to the fields, but I don’t think it should matter in the Unit. This is probably optimised to the same thing? Not sure though. I don’t think it matters that much.
There’s probably some kind of way of doing this with pure functions that inlines functions more aggressively, as well.
Implementations§
source§impl SimultaneousUnsafeAssignment
impl SimultaneousUnsafeAssignment
pub fn with<'b, Dst: UnsafeAssign<T>, T>( self, value: T, dst: &'b mut Dst ) -> DeferredSimultaneousUnsafeAssignment<Self, DeferredUnsafeAssignment<'b, Dst, T>>
Trait Implementations§
Auto Trait Implementations§
impl RefUnwindSafe for SimultaneousUnsafeAssignment
impl Send for SimultaneousUnsafeAssignment
impl Sync for SimultaneousUnsafeAssignment
impl Unpin for SimultaneousUnsafeAssignment
impl UnwindSafe for SimultaneousUnsafeAssignment
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more