Skip to content

Commit

Permalink
Merge pull request #510 from Skepfyr/update-option
Browse files Browse the repository at this point in the history
Implement Update for Option<T>
  • Loading branch information
nikomatsakis committed Jun 23, 2024
2 parents f706aa2 + db4c0de commit 091421b
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -360,3 +360,20 @@ tuple_impl!(A, B, C, D, E, F, G, H, I; a, b, c, d, e, f, g, h, i);
tuple_impl!(A, B, C, D, E, F, G, H, I, J; a, b, c, d, e, f, g, h, i, j);
tuple_impl!(A, B, C, D, E, F, G, H, I, J, K; a, b, c, d, e, f, g, h, i, j, k);
tuple_impl!(A, B, C, D, E, F, G, H, I, J, K, L; a, b, c, d, e, f, g, h, i, j, k, l);

unsafe impl<T> Update for Option<T>
where
T: Update,
{
unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool {
let old_value = unsafe { &mut *old_pointer };
match (old_value, new_value) {
(Some(old), Some(new)) => T::maybe_update(old, new),
(None, None) => false,
(old_value, new_value) => {
*old_value = new_value;
true
}
}
}
}

0 comments on commit 091421b

Please sign in to comment.