Skip to content

Commit 091421b

Browse files
authored
Merge pull request #510 from Skepfyr/update-option
Implement Update for Option<T>
2 parents f706aa2 + db4c0de commit 091421b

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/update.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,3 +360,20 @@ tuple_impl!(A, B, C, D, E, F, G, H, I; a, b, c, d, e, f, g, h, i);
360360
tuple_impl!(A, B, C, D, E, F, G, H, I, J; a, b, c, d, e, f, g, h, i, j);
361361
tuple_impl!(A, B, C, D, E, F, G, H, I, J, K; a, b, c, d, e, f, g, h, i, j, k);
362362
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);
363+
364+
unsafe impl<T> Update for Option<T>
365+
where
366+
T: Update,
367+
{
368+
unsafe fn maybe_update(old_pointer: *mut Self, new_value: Self) -> bool {
369+
let old_value = unsafe { &mut *old_pointer };
370+
match (old_value, new_value) {
371+
(Some(old), Some(new)) => T::maybe_update(old, new),
372+
(None, None) => false,
373+
(old_value, new_value) => {
374+
*old_value = new_value;
375+
true
376+
}
377+
}
378+
}
379+
}

0 commit comments

Comments
 (0)