From 9eeff6caf69b99f0ccf0220411d90b32d8e1d4d6 Mon Sep 17 00:00:00 2001 From: Jesse Hoobergs <jesse@codebergs.com> Date: Tue, 18 Jan 2022 14:24:40 +0100 Subject: [PATCH] Add implementation for Box Taken from https://github.com/amethyst/serde-diff/pull/37 --- src/implementation.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/implementation.rs b/src/implementation.rs index cec6df1..346dc58 100644 --- a/src/implementation.rs +++ b/src/implementation.rs @@ -409,3 +409,27 @@ impl<T: SerdeDiff + Serialize + for<'a> Deserialize<'a>> SerdeDiff for Option<T> type Unit = (); opaque_serde_diff!(Unit); + +impl<T> SerdeDiff for Box<T> +where + T: SerdeDiff, +{ + fn diff<'a, S: SerializeSeq>( + &self, + ctx: &mut crate::difference::DiffContext<'a, S>, + other: &Self, + ) -> Result<bool, S::Error> { + self.as_ref().diff(ctx, other) + } + + fn apply<'de, A>( + &mut self, + seq: &mut A, + ctx: &mut crate::apply::ApplyContext, + ) -> Result<bool, <A as serde::de::SeqAccess<'de>>::Error> + where + A: de::SeqAccess<'de>, + { + self.as_mut().apply(seq, ctx) + } +}