1use crate::{from_intermediate, Change, Intermediate};
2use serde::de::DeserializeOwned;
3use std::{
4 cell::Cell,
5 collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, LinkedList, VecDeque},
6 hash::Hash,
7 marker::PhantomData,
8 num::{
9 NonZeroI128, NonZeroI16, NonZeroI32, NonZeroI64, NonZeroI8, NonZeroIsize, NonZeroU128,
10 NonZeroU16, NonZeroU32, NonZeroU64, NonZeroU8, NonZeroUsize,
11 },
12 ops::{Range, RangeInclusive},
13 path::PathBuf,
14 sync::{
15 atomic::{
16 AtomicBool, AtomicI16, AtomicI32, AtomicI64, AtomicI8, AtomicIsize, AtomicU16,
17 AtomicU32, AtomicU64, AtomicU8, AtomicUsize,
18 },
19 Mutex,
20 },
21};
22
23pub trait ReflectIntermediate {
41 fn patch_change(&mut self, _change: &Change) {}
42
43 fn before_patch_change(&mut self) {}
44
45 fn after_patch_change(&mut self) {}
46}
47
48macro_rules! impl_reflect {
49 (@atom $type:ty => $( $variant:ident ),+ ) => {
50 impl ReflectIntermediate for $type {
51 fn patch_change(&mut self, change: &Change) {
52 #[allow(clippy::collapsible_match)]
53 if let Change::Changed(v) = change {
54 match v {
55 $(
56 #[allow(irrefutable_let_patterns)]
57 Intermediate::$variant(v) => if let Ok(v) = Self::try_from(*v) {
58 *self = v;
59 }
60 )+
61 _ => {}
62 }
63 }
64 }
65 }
66 };
67 (@cast $type:ty => $cast:ty => $( $variant:ident ),+ ) => {
68 impl ReflectIntermediate for $type {
69 fn patch_change(&mut self, change: &Change) {
70 #[allow(clippy::collapsible_match)]
71 if let Change::Changed(v) = change {
72 match v {
73 $(
74 #[allow(irrefutable_let_patterns)]
75 Intermediate::$variant(v) => if let Ok(v) = <$cast>::try_from(*v) {
76 if let Ok(v) = Self::try_from(v) {
77 *self = v.into();
78 }
79 }
80 )+
81 _ => {}
82 }
83 }
84 }
85 }
86 };
87}
88
89impl ReflectIntermediate for () {}
90impl<T> ReflectIntermediate for PhantomData<T> {}
91
92impl_reflect!(@atom bool => Bool);
93impl_reflect!(@atom i8 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
94impl_reflect!(@atom i16 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
95impl_reflect!(@atom i32 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
96impl_reflect!(@atom i64 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
97impl_reflect!(@atom i128 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
98impl_reflect!(@atom isize => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
99impl_reflect!(@atom u8 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
100impl_reflect!(@atom u16 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
101impl_reflect!(@atom u32 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
102impl_reflect!(@atom u64 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
103impl_reflect!(@atom u128 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
104impl_reflect!(@atom usize => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
105impl_reflect!(@atom f32 => I8, I16, U8, U16, F32);
106impl_reflect!(@atom f64 => I8, I16, I32, U8, U16, U32, F32, F64);
107impl_reflect!(@atom char => U8, U32, Char);
108impl_reflect!(@cast AtomicBool => bool => Bool);
109impl_reflect!(@cast AtomicI8 => i8 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
110impl_reflect!(@cast AtomicI16 => i16 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
111impl_reflect!(@cast AtomicI32 => i32 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
112impl_reflect!(@cast AtomicI64 => i64 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
113impl_reflect!(@cast AtomicIsize => isize => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
114impl_reflect!(@cast AtomicU8 => u8 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
115impl_reflect!(@cast AtomicU16 => u16 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
116impl_reflect!(@cast AtomicU32 => u32 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
117impl_reflect!(@cast AtomicU64 => u64 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
118impl_reflect!(@cast AtomicUsize => usize => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
119impl_reflect!(@cast NonZeroI8 => i8 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
120impl_reflect!(@cast NonZeroI16 => i16 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
121impl_reflect!(@cast NonZeroI32 => i32 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
122impl_reflect!(@cast NonZeroI64 => i64 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
123impl_reflect!(@cast NonZeroI128 => i128 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
124impl_reflect!(@cast NonZeroIsize => isize => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
125impl_reflect!(@cast NonZeroU8 => u8 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
126impl_reflect!(@cast NonZeroU16 => u16 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
127impl_reflect!(@cast NonZeroU32 => u32 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
128impl_reflect!(@cast NonZeroU64 => u64 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
129impl_reflect!(@cast NonZeroU128 => u128 => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128, Char);
130impl_reflect!(@cast NonZeroUsize => usize => Bool, I8, I16, I32, I64, I128, U8, U16, U32, U64, U128);
131
132impl ReflectIntermediate for String {
133 fn patch_change(&mut self, change: &Change) {
134 if let Change::Changed(v) = change {
135 match v {
136 Intermediate::Char(v) => *self = v.to_string(),
137 Intermediate::String(v) => *self = v.to_owned(),
138 _ => {}
139 }
140 }
141 }
142}
143
144impl ReflectIntermediate for PathBuf {
145 fn patch_change(&mut self, change: &Change) {
146 if let Change::Changed(v) = change {
147 match v {
148 Intermediate::Char(v) => *self = v.to_string().into(),
149 Intermediate::String(v) => *self = v.into(),
150 _ => {}
151 }
152 }
153 }
154}
155
156impl<T, const N: usize> ReflectIntermediate for [T; N]
157where
158 T: ReflectIntermediate + DeserializeOwned,
159{
160 fn patch_change(&mut self, change: &Change) {
161 match change {
162 Change::Changed(Intermediate::Seq(v)) => {
163 for (item, v) in self.iter_mut().zip(v.iter()) {
164 if let Ok(v) = from_intermediate(v) {
165 *item = v;
166 }
167 }
168 }
169 Change::PartialSeq(v) => {
170 for (index, change) in v {
171 if *index < N {
172 self[*index].patch_change(change);
173 }
174 }
175 }
176 _ => {}
177 }
178 }
179}
180
181impl<T> ReflectIntermediate for (T,)
182where
183 T: ReflectIntermediate + DeserializeOwned,
184{
185 fn patch_change(&mut self, change: &Change) {
186 match change {
187 Change::Changed(Intermediate::Seq(v)) => {
188 if let Some(v) = v.first() {
189 if let Ok(v) = from_intermediate(v) {
190 self.0 = v;
191 }
192 }
193 }
194 Change::PartialSeq(v) => {
195 for (index, change) in v {
196 if *index == 0 {
197 self.0.patch_change(change);
198 }
199 }
200 }
201 _ => {}
202 }
203 }
204}
205
206macro_rules! impl_tuple {
207 ( $( $id:ident : $index:tt ),+ ) => {
208 impl< $( $id ),+ > ReflectIntermediate for ( $( $id ),+ )
209 where
210 $( $id: ReflectIntermediate + DeserializeOwned ),+
211 {
212 fn patch_change(&mut self, change: &Change) {
213 match change {
214 Change::Changed(Intermediate::Seq(v)) => {
215 $(
216 if let Some(v) = v.get($index) {
217 if let Ok(v) = from_intermediate(v) {
218 self.$index = v;
219 }
220 }
221 )+
222 }
223 Change::PartialSeq(v) => {
224 $(
225 if let Some((_,change)) = v.iter().find(|(i,_)| *i == $index) {
226 self.$index.patch_change(change);
227 }
228 )+
229 }
230 _ => {}
231 }
232 }
233 }
234 };
235}
236
237impl_tuple! { A:0, B:1 }
238impl_tuple! { A:0, B:1, C:2 }
239impl_tuple! { A:0, B:1, C:2, D:3 }
240impl_tuple! { A:0, B:1, C:2, D:3, E:4 }
241impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5 }
242impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6 }
243impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7 }
244impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8 }
245impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9 }
246impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10 }
247impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11 }
248impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12 }
249impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13 }
250impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14 }
251impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15 }
252impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16 }
253impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17 }
254impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18 }
255impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19 }
256impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20 }
257impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21 }
258impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21, X:22 }
259impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21, X:22, Y:23 }
260impl_tuple! { A:0, B:1, C:2, D:3, E:4, F:5, G:6, H:7, I:8, J:9, K:10, L:11, M:12, N:13, O:14, P:15, Q:16, R:17, S:18, T:19, U:20, V:21, X:22, Y:23, Z:24 }
261
262impl<T> ReflectIntermediate for Vec<T>
263where
264 T: ReflectIntermediate + DeserializeOwned,
265{
266 fn patch_change(&mut self, change: &Change) {
267 match change {
268 Change::Changed(v) => {
269 if let Ok(v) = from_intermediate(v) {
270 *self = v;
271 }
272 }
273 Change::PartialSeq(v) => {
274 for (index, change) in v {
275 match change {
276 Change::Removed => {
277 self.remove(*index);
278 }
279 Change::Added(v) => {
280 if let Ok(v) = from_intermediate(v) {
281 self.insert(*index, v);
282 }
283 }
284 change => {
285 if let Some(item) = self.get_mut(*index) {
286 item.patch_change(change);
287 }
288 }
289 }
290 }
291 }
292 _ => {}
293 }
294 }
295}
296
297impl<T> ReflectIntermediate for VecDeque<T>
298where
299 T: ReflectIntermediate + DeserializeOwned,
300{
301 fn patch_change(&mut self, change: &Change) {
302 match change {
303 Change::Changed(v) => {
304 if let Ok(v) = from_intermediate(v) {
305 *self = v;
306 }
307 }
308 Change::PartialSeq(v) => {
309 for (index, change) in v {
310 match change {
311 Change::Removed => {
312 self.remove(*index);
313 }
314 Change::Added(v) => {
315 if let Ok(v) = from_intermediate(v) {
316 self.insert(*index, v);
317 }
318 }
319 change => {
320 if let Some(item) = self.get_mut(*index) {
321 item.patch_change(change);
322 }
323 }
324 }
325 }
326 }
327 _ => {}
328 }
329 }
330}
331
332impl<T> ReflectIntermediate for HashSet<T>
333where
334 T: ReflectIntermediate + DeserializeOwned + Hash + Eq + Clone,
335{
336 fn patch_change(&mut self, change: &Change) {
337 match change {
338 Change::Changed(v) => {
339 if let Ok(v) = from_intermediate(v) {
340 *self = v;
341 }
342 }
343 Change::PartialSeq(v) => {
344 let mut data = self.iter().cloned().collect::<Vec<_>>();
345 for (index, change) in v {
346 match change {
347 Change::Removed => {
348 data.remove(*index);
349 }
350 Change::Added(v) => {
351 if let Ok(v) = from_intermediate(v) {
352 data.insert(*index, v);
353 }
354 }
355 change => {
356 if let Some(item) = data.get_mut(*index) {
357 item.patch_change(change);
358 }
359 }
360 }
361 }
362 *self = data.into_iter().collect();
363 }
364 _ => {}
365 }
366 }
367}
368
369impl<T> ReflectIntermediate for BTreeSet<T>
370where
371 T: ReflectIntermediate + DeserializeOwned + Ord + Clone,
372{
373 fn patch_change(&mut self, change: &Change) {
374 match change {
375 Change::Changed(v) => {
376 if let Ok(v) = from_intermediate(v) {
377 *self = v;
378 }
379 }
380 Change::PartialSeq(v) => {
381 let mut data = self.iter().cloned().collect::<Vec<_>>();
382 for (index, change) in v {
383 match change {
384 Change::Removed => {
385 data.remove(*index);
386 }
387 Change::Added(v) => {
388 if let Ok(v) = from_intermediate(v) {
389 data.insert(*index, v);
390 }
391 }
392 change => {
393 if let Some(item) = data.get_mut(*index) {
394 item.patch_change(change);
395 }
396 }
397 }
398 }
399 *self = data.into_iter().collect();
400 }
401 _ => {}
402 }
403 }
404}
405
406impl<T> ReflectIntermediate for LinkedList<T>
407where
408 T: ReflectIntermediate + DeserializeOwned + Clone,
409{
410 fn patch_change(&mut self, change: &Change) {
411 match change {
412 Change::Changed(v) => {
413 if let Ok(v) = from_intermediate(v) {
414 *self = v;
415 }
416 }
417 Change::PartialSeq(v) => {
418 let mut data = self.iter().cloned().collect::<Vec<_>>();
419 for (index, change) in v {
420 match change {
421 Change::Removed => {
422 data.remove(*index);
423 }
424 Change::Added(v) => {
425 if let Ok(v) = from_intermediate(v) {
426 data.insert(*index, v);
427 }
428 }
429 change => {
430 if let Some(item) = data.get_mut(*index) {
431 item.patch_change(change);
432 }
433 }
434 }
435 }
436 *self = data.into_iter().collect();
437 }
438 _ => {}
439 }
440 }
441}
442
443impl<T> ReflectIntermediate for BinaryHeap<T>
444where
445 T: ReflectIntermediate + DeserializeOwned + Ord + Clone,
446{
447 fn patch_change(&mut self, change: &Change) {
448 match change {
449 Change::Changed(v) => {
450 if let Ok(v) = from_intermediate(v) {
451 *self = v;
452 }
453 }
454 Change::PartialSeq(v) => {
455 let mut data = self.iter().cloned().collect::<Vec<_>>();
456 for (index, change) in v {
457 match change {
458 Change::Removed => {
459 data.remove(*index);
460 }
461 Change::Added(v) => {
462 if let Ok(v) = from_intermediate(v) {
463 data.insert(*index, v);
464 }
465 }
466 change => {
467 if let Some(item) = data.get_mut(*index) {
468 item.patch_change(change);
469 }
470 }
471 }
472 }
473 *self = data.into_iter().collect();
474 }
475 _ => {}
476 }
477 }
478}
479
480impl<K, V> ReflectIntermediate for HashMap<K, V>
481where
482 K: ReflectIntermediate + DeserializeOwned + Hash + Eq,
483 V: ReflectIntermediate + DeserializeOwned,
484{
485 fn patch_change(&mut self, change: &Change) {
486 match change {
487 Change::Changed(v) => {
488 if let Ok(v) = from_intermediate(v) {
489 *self = v;
490 }
491 }
492 Change::PartialMap(v) => {
493 for (key, change) in v {
494 if let Ok(key) = from_intermediate(key) {
495 match change {
496 Change::Removed => {
497 self.remove(&key);
498 }
499 Change::Added(v) => {
500 if let Ok(v) = from_intermediate(v) {
501 self.insert(key, v);
502 }
503 }
504 change => {
505 if let Some(item) = self.get_mut(&key) {
506 item.patch_change(change);
507 }
508 }
509 }
510 }
511 }
512 }
513 _ => {}
514 }
515 }
516}
517
518impl<K, V> ReflectIntermediate for BTreeMap<K, V>
519where
520 K: ReflectIntermediate + DeserializeOwned + Ord,
521 V: ReflectIntermediate + DeserializeOwned,
522{
523 fn patch_change(&mut self, change: &Change) {
524 match change {
525 Change::Changed(v) => {
526 if let Ok(v) = from_intermediate(v) {
527 *self = v;
528 }
529 }
530 Change::PartialMap(v) => {
531 for (key, change) in v {
532 if let Ok(key) = from_intermediate(key) {
533 match change {
534 Change::Removed => {
535 self.remove(&key);
536 }
537 Change::Added(v) => {
538 if let Ok(v) = from_intermediate(v) {
539 self.insert(key, v);
540 }
541 }
542 change => {
543 if let Some(item) = self.get_mut(&key) {
544 item.patch_change(change);
545 }
546 }
547 }
548 }
549 }
550 }
551 _ => {}
552 }
553 }
554}
555
556impl<T> ReflectIntermediate for Box<T>
557where
558 T: ReflectIntermediate + DeserializeOwned,
559{
560 fn patch_change(&mut self, change: &Change) {
561 match change {
562 Change::Changed(v) => {
563 if let Ok(v) = from_intermediate(v) {
564 *self = v;
565 }
566 }
567 Change::PartialChange(change) => {
568 self.patch_change(change);
569 }
570 _ => {}
571 }
572 }
573}
574
575impl<T> ReflectIntermediate for Option<T>
576where
577 T: ReflectIntermediate + DeserializeOwned,
578{
579 fn patch_change(&mut self, change: &Change) {
580 match change {
581 Change::Changed(v) => {
582 if let Ok(v) = from_intermediate(v) {
583 *self = v;
584 }
585 }
586 Change::PartialChange(change) => {
587 if let Some(content) = self {
588 content.patch_change(change);
589 }
590 }
591 _ => {}
592 }
593 }
594}
595
596impl<T, E> ReflectIntermediate for Result<T, E>
597where
598 T: ReflectIntermediate + DeserializeOwned,
599 E: ReflectIntermediate + DeserializeOwned,
600{
601 fn patch_change(&mut self, change: &Change) {
602 match change {
603 Change::Changed(v) => {
604 if let Ok(v) = from_intermediate(v) {
605 *self = v;
606 }
607 }
608 Change::PartialChange(change) => match self {
609 Ok(content) => content.patch_change(change),
610 Err(content) => content.patch_change(change),
611 },
612 _ => {}
613 }
614 }
615}
616
617impl<T> ReflectIntermediate for Cell<T>
618where
619 T: ReflectIntermediate + DeserializeOwned,
620{
621 fn patch_change(&mut self, change: &Change) {
622 match change {
623 Change::Changed(v) => {
624 if let Ok(v) = from_intermediate(v) {
625 self.set(v);
626 }
627 }
628 Change::PartialChange(change) => {
629 self.patch_change(change);
630 }
631 _ => {}
632 }
633 }
634}
635
636impl<T> ReflectIntermediate for Mutex<T>
637where
638 T: ReflectIntermediate + DeserializeOwned,
639{
640 fn patch_change(&mut self, change: &Change) {
641 match change {
642 Change::Changed(v) => {
643 if let Ok(v) = from_intermediate(v) {
644 if let Ok(ref mut mutex) = self.try_lock() {
645 **mutex = v;
646 }
647 }
648 }
649 Change::PartialChange(change) => {
650 self.patch_change(change);
651 }
652 _ => {}
653 }
654 }
655}
656
657impl<T> ReflectIntermediate for Range<T>
658where
659 T: ReflectIntermediate + DeserializeOwned,
660{
661 fn patch_change(&mut self, change: &Change) {
662 match change {
663 Change::Changed(v) => {
664 if let Ok(v) = from_intermediate(v) {
665 *self = v;
666 }
667 }
668 Change::PartialStruct(v) => {
669 for (key, change) in v {
670 match key.as_str() {
671 "start" => self.start.patch_change(change),
672 "end" => self.end.patch_change(change),
673 _ => {}
674 }
675 }
676 }
677 _ => {}
678 }
679 }
680}
681
682impl<T> ReflectIntermediate for RangeInclusive<T>
683where
684 T: ReflectIntermediate + DeserializeOwned + Clone,
685{
686 fn patch_change(&mut self, change: &Change) {
687 match change {
688 Change::Changed(v) => {
689 if let Ok(v) = from_intermediate(v) {
690 *self = v;
691 }
692 }
693 Change::PartialStruct(v) => {
694 let (mut start, mut end) = self.clone().into_inner();
695 for (key, change) in v {
696 match key.as_str() {
697 "start" => start.patch_change(change),
698 "end" => end.patch_change(change),
699 _ => {}
700 }
701 }
702 *self = Self::new(start, end);
703 }
704 _ => {}
705 }
706 }
707}