From db4c0de45ca16e245df2dc6be0ad6cc6ee62e561 Mon Sep 17 00:00:00 2001 From: Jack Rickard Date: Fri, 21 Jun 2024 14:37:12 +0100 Subject: [PATCH] Implement Update for Option --- src/update.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/update.rs b/src/update.rs index e8f5f7e1..3313746f 100644 --- a/src/update.rs +++ b/src/update.rs @@ -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 Update for Option +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 + } + } + } +}