1pub use key_paths_core::{AccessorTrait, KeyPath, KeyPathValueTarget, KpTrait, Readable, Writable};
6
7use crate::Kp;
8
9pub trait ChainExt<R, V, Root, Value, MutRoot, MutValue> {
10 fn then_sync<
12 Lock,
13 Mid,
14 V2,
15 LockValue,
16 MidValue,
17 Value2,
18 MutLock,
19 MutMid,
20 MutValue2,
21 G1,
22 S1,
23 L,
24 G2,
25 S2,
26 >(
27 self,
28 lock_kp: crate::sync_kp::SyncKp<
29 V,
30 Lock,
31 Mid,
32 V2,
33 Value,
34 LockValue,
35 MidValue,
36 Value2,
37 MutValue,
38 MutLock,
39 MutMid,
40 MutValue2,
41 G1,
42 S1,
43 L,
44 G2,
45 S2,
46 >,
47 ) -> crate::sync_kp::KpThenSyncKp<
48 R,
49 V,
50 V2,
51 Root,
52 Value,
53 Value2,
54 MutRoot,
55 MutValue,
56 MutValue2,
57 Self,
58 crate::sync_kp::SyncKp<
59 V,
60 Lock,
61 Mid,
62 V2,
63 Value,
64 LockValue,
65 MidValue,
66 Value2,
67 MutValue,
68 MutLock,
69 MutMid,
70 MutValue2,
71 G1,
72 S1,
73 L,
74 G2,
75 S2,
76 >,
77 >
78 where
79 V: 'static,
80 V2: 'static,
81 Value: std::borrow::Borrow<V>,
82 Value2: std::borrow::Borrow<V2>,
83 MutValue: std::borrow::BorrowMut<V>,
84 MutValue2: std::borrow::BorrowMut<V2>,
85 LockValue: std::borrow::Borrow<Lock>,
86 MidValue: std::borrow::Borrow<Mid>,
87 MutLock: std::borrow::BorrowMut<Lock>,
88 MutMid: std::borrow::BorrowMut<Mid>,
89 G1: Fn(Value) -> Option<LockValue>,
90 S1: Fn(MutValue) -> Option<MutLock>,
91 L: crate::sync_kp::LockAccess<Lock, MidValue> + crate::sync_kp::LockAccess<Lock, MutMid>,
92 G2: Fn(MidValue) -> Option<Value2>,
93 S2: Fn(MutMid) -> Option<MutValue2>,
94 Self: Sized;
95
96 #[cfg(feature = "pin_project")]
98 fn then_pin_future<Struct, Output, L>(
99 self,
100 pin_fut: L,
101 ) -> crate::pin::KpThenPinFuture<R, Struct, Output, Root, MutRoot, Value, MutValue, Self, L>
102 where
103 Struct: std::marker::Unpin + 'static,
104 Output: 'static,
105 Value: std::borrow::Borrow<Struct>,
106 MutValue: std::borrow::BorrowMut<Struct>,
107 L: crate::pin::PinFutureAwaitLike<Struct, Output> + Sync,
108 Self: Sized;
109
110 fn then_async<AsyncKp>(
112 self,
113 async_kp: AsyncKp,
114 ) -> crate::async_lock::KpThenAsyncKeyPath<
115 R,
116 V,
117 <AsyncKp::Value as KeyPathValueTarget>::Target,
118 Root,
119 Value,
120 AsyncKp::Value,
121 MutRoot,
122 MutValue,
123 AsyncKp::MutValue,
124 Self,
125 AsyncKp,
126 >
127 where
128 Value: std::borrow::Borrow<V>,
129 MutValue: std::borrow::BorrowMut<V>,
130 AsyncKp: crate::async_lock::AsyncKeyPathLike<Value, MutValue>,
131 AsyncKp::Value: KeyPathValueTarget
132 + std::borrow::Borrow<<AsyncKp::Value as KeyPathValueTarget>::Target>,
133 AsyncKp::MutValue: std::borrow::BorrowMut<<AsyncKp::Value as KeyPathValueTarget>::Target>,
134 <AsyncKp::Value as KeyPathValueTarget>::Target: 'static,
135 Self: Sized;
136}
137
138impl<R, V, Root, Value, MutRoot, MutValue, G, S> ChainExt<R, V, Root, Value, MutRoot, MutValue>
139 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
140where
141 Root: std::borrow::Borrow<R>,
142 Value: std::borrow::Borrow<V>,
143 MutRoot: std::borrow::BorrowMut<R>,
144 MutValue: std::borrow::BorrowMut<V>,
145 G: Fn(Root) -> Option<Value>,
146 S: Fn(MutRoot) -> Option<MutValue>,
147{
148 fn then_sync<
149 Lock,
150 Mid,
151 V2,
152 LockValue,
153 MidValue,
154 Value2,
155 MutLock,
156 MutMid,
157 MutValue2,
158 G1,
159 S1,
160 L,
161 G2,
162 S2,
163 >(
164 self,
165 lock_kp: crate::sync_kp::SyncKp<
166 V,
167 Lock,
168 Mid,
169 V2,
170 Value,
171 LockValue,
172 MidValue,
173 Value2,
174 MutValue,
175 MutLock,
176 MutMid,
177 MutValue2,
178 G1,
179 S1,
180 L,
181 G2,
182 S2,
183 >,
184 ) -> crate::sync_kp::KpThenSyncKp<
185 R,
186 V,
187 V2,
188 Root,
189 Value,
190 Value2,
191 MutRoot,
192 MutValue,
193 MutValue2,
194 Self,
195 crate::sync_kp::SyncKp<
196 V,
197 Lock,
198 Mid,
199 V2,
200 Value,
201 LockValue,
202 MidValue,
203 Value2,
204 MutValue,
205 MutLock,
206 MutMid,
207 MutValue2,
208 G1,
209 S1,
210 L,
211 G2,
212 S2,
213 >,
214 >
215 where
216 V: 'static,
217 V2: 'static,
218 Value: std::borrow::Borrow<V>,
219 Value2: std::borrow::Borrow<V2>,
220 MutValue: std::borrow::BorrowMut<V>,
221 MutValue2: std::borrow::BorrowMut<V2>,
222 LockValue: std::borrow::Borrow<Lock>,
223 MidValue: std::borrow::Borrow<Mid>,
224 MutLock: std::borrow::BorrowMut<Lock>,
225 MutMid: std::borrow::BorrowMut<Mid>,
226 G1: Fn(Value) -> Option<LockValue>,
227 S1: Fn(MutValue) -> Option<MutLock>,
228 L: crate::sync_kp::LockAccess<Lock, MidValue> + crate::sync_kp::LockAccess<Lock, MutMid>,
229 G2: Fn(MidValue) -> Option<Value2>,
230 S2: Fn(MutMid) -> Option<MutValue2>,
231 {
232 let first = self;
233 let second = lock_kp;
234
235 crate::sync_kp::KpThenSyncKp::new(first, second)
236 }
237
238 #[cfg(feature = "pin_project")]
239 fn then_pin_future<Struct, Output, L>(
240 self,
241 pin_fut: L,
242 ) -> crate::pin::KpThenPinFuture<R, Struct, Output, Root, MutRoot, Value, MutValue, Self, L>
243 where
244 Struct: std::marker::Unpin + 'static,
245 Output: 'static,
246 Value: std::borrow::Borrow<Struct>,
247 MutValue: std::borrow::BorrowMut<Struct>,
248 L: crate::pin::PinFutureAwaitLike<Struct, Output> + Sync,
249 {
250 let first = self;
251 let second = pin_fut;
252
253 crate::pin::KpThenPinFuture::new(first, second)
254 }
255
256 fn then_async<AsyncKp>(
257 self,
258 async_kp: AsyncKp,
259 ) -> crate::async_lock::KpThenAsyncKeyPath<
260 R,
261 V,
262 <AsyncKp::Value as KeyPathValueTarget>::Target,
263 Root,
264 Value,
265 AsyncKp::Value,
266 MutRoot,
267 MutValue,
268 AsyncKp::MutValue,
269 Self,
270 AsyncKp,
271 >
272 where
273 Value: std::borrow::Borrow<V>,
274 MutValue: std::borrow::BorrowMut<V>,
275 AsyncKp: crate::async_lock::AsyncKeyPathLike<Value, MutValue>,
276 AsyncKp::Value: KeyPathValueTarget
277 + std::borrow::Borrow<<AsyncKp::Value as KeyPathValueTarget>::Target>,
278 AsyncKp::MutValue: std::borrow::BorrowMut<<AsyncKp::Value as KeyPathValueTarget>::Target>,
279 <AsyncKp::Value as KeyPathValueTarget>::Target: 'static,
280 {
281 let first = self;
282 let second = async_kp;
283
284 crate::async_lock::KpThenAsyncKeyPath::new(first, second)
285 }
286}
287
288pub trait CoercionTrait<R, V, Root, Value, MutRoot, MutValue, G, S>:
289 KpTrait<R, V, Root, Value, MutRoot, MutValue>
290where
291 Root: std::borrow::Borrow<R>,
292 Value: std::borrow::Borrow<V>,
293 MutRoot: std::borrow::BorrowMut<R>,
294 MutValue: std::borrow::BorrowMut<V>,
295 G: Fn(Root) -> Option<Value>,
296 S: Fn(MutRoot) -> Option<MutValue>,
297{
298 fn for_arc<'b>(
299 &self,
300 ) -> Kp<
301 std::sync::Arc<R>,
302 V,
303 std::sync::Arc<R>,
304 Value,
305 std::sync::Arc<R>,
306 MutValue,
307 impl Fn(std::sync::Arc<R>) -> Option<Value>,
308 impl Fn(std::sync::Arc<R>) -> Option<MutValue>,
309 >
310 where
311 R: 'b,
312 V: 'b,
313 Root: for<'a> From<&'a R>,
314 MutRoot: for<'a> From<&'a mut R>;
315
316 fn for_box<'a>(
317 &self,
318 ) -> Kp<
319 Box<R>,
320 V,
321 Box<R>,
322 Value,
323 Box<R>,
324 MutValue,
325 impl Fn(Box<R>) -> Option<Value>,
326 impl Fn(Box<R>) -> Option<MutValue>,
327 >
328 where
329 R: 'a,
330 V: 'a,
331 Root: for<'b> From<&'b R>,
332 MutRoot: for<'b> From<&'b mut R>;
333
334 fn into_set(self) -> impl Fn(MutRoot) -> Option<MutValue>;
335
336 fn into_get(self) -> impl Fn(Root) -> Option<Value>;
337}
338
339pub trait HofTrait<R, V, Root, Value, MutRoot, MutValue, G, S>:
340 KpTrait<R, V, Root, Value, MutRoot, MutValue>
341where
342 Root: std::borrow::Borrow<R>,
343 Value: std::borrow::Borrow<V>,
344 MutRoot: std::borrow::BorrowMut<R>,
345 MutValue: std::borrow::BorrowMut<V>,
346 G: Fn(Root) -> Option<Value>,
347 S: Fn(MutRoot) -> Option<MutValue>,
348{
349 fn map<MappedValue, F>(
350 &self,
351 mapper: F,
352 ) -> Kp<
353 R,
354 MappedValue,
355 Root,
356 MappedValue,
357 MutRoot,
358 MappedValue,
359 impl Fn(Root) -> Option<MappedValue> + '_,
360 impl Fn(MutRoot) -> Option<MappedValue> + '_,
361 >
362 where
363 F: Fn(&V) -> MappedValue + Copy + 'static,
364 MappedValue: 'static,
365 {
366 Kp::new(
367 move |root: Root| {
368 Readable::get(self, root).map(|value| {
369 let v: &V = value.borrow();
370 mapper(v)
371 })
372 },
373 move |root: MutRoot| {
374 Writable::set(self, root).map(|value| {
375 let v: &V = value.borrow();
376 mapper(v)
377 })
378 },
379 )
380 }
381
382 fn filter<F>(
383 &self,
384 predicate: F,
385 ) -> Kp<
386 R,
387 V,
388 Root,
389 Value,
390 MutRoot,
391 MutValue,
392 impl Fn(Root) -> Option<Value> + '_,
393 impl Fn(MutRoot) -> Option<MutValue> + '_,
394 >
395 where
396 F: Fn(&V) -> bool + Copy + 'static,
397 {
398 Kp::new(
399 move |root: Root| {
400 Readable::get(self, root).filter(|value| {
401 let v: &V = value.borrow();
402 predicate(v)
403 })
404 },
405 move |root: MutRoot| {
406 Writable::set(self, root).filter(|value| {
407 let v: &V = value.borrow();
408 predicate(v)
409 })
410 },
411 )
412 }
413
414 fn filter_map<MappedValue, F>(
415 &self,
416 mapper: F,
417 ) -> Kp<
418 R,
419 MappedValue,
420 Root,
421 MappedValue,
422 MutRoot,
423 MappedValue,
424 impl Fn(Root) -> Option<MappedValue> + '_,
425 impl Fn(MutRoot) -> Option<MappedValue> + '_,
426 >
427 where
428 F: Fn(&V) -> Option<MappedValue> + Copy + 'static,
429 {
430 Kp::new(
431 move |root: Root| {
432 Readable::get(self, root).and_then(|value| {
433 let v: &V = value.borrow();
434 mapper(v)
435 })
436 },
437 move |root: MutRoot| {
438 Writable::set(self, root).and_then(|value| {
439 let v: &V = value.borrow();
440 mapper(v)
441 })
442 },
443 )
444 }
445
446 fn inspect<F>(
447 &self,
448 inspector: F,
449 ) -> Kp<
450 R,
451 V,
452 Root,
453 Value,
454 MutRoot,
455 MutValue,
456 impl Fn(Root) -> Option<Value> + '_,
457 impl Fn(MutRoot) -> Option<MutValue> + '_,
458 >
459 where
460 F: Fn(&V) + Clone + 'static,
461 {
462 let inspector_for_get = inspector.clone();
463 Kp::new(
464 move |root: Root| {
465 Readable::get(self, root).map(|value| {
466 let v: &V = value.borrow();
467 inspector_for_get(v);
468 value
469 })
470 },
471 move |root: MutRoot| {
472 Writable::set(self, root).map(|value| {
473 let v: &V = value.borrow();
474 inspector(v);
475 value
476 })
477 },
478 )
479 }
480
481 fn flat_map<I, Item, F>(&self, mapper: F) -> impl Fn(Root) -> Vec<Item> + '_
482 where
483 F: Fn(&V) -> I + 'static,
484 I: IntoIterator<Item = Item>,
485 {
486 move |root: Root| {
487 Readable::get(self, root)
488 .map(|value| {
489 let v: &V = value.borrow();
490 mapper(v).into_iter().collect()
491 })
492 .unwrap_or_else(Vec::new)
493 }
494 }
495
496 fn fold_value<Acc, F>(&self, init: Acc, folder: F) -> impl Fn(Root) -> Acc + '_
497 where
498 F: Fn(Acc, &V) -> Acc + 'static,
499 Acc: Copy + 'static,
500 {
501 move |root: Root| {
502 Readable::get(self, root)
503 .map(|value| {
504 let v: &V = value.borrow();
505 folder(init, v)
506 })
507 .unwrap_or(init)
508 }
509 }
510
511 fn any<F>(&self, predicate: F) -> impl Fn(Root) -> bool + '_
512 where
513 F: Fn(&V) -> bool + 'static,
514 {
515 move |root: Root| {
516 Readable::get(self, root)
517 .map(|value| {
518 let v: &V = value.borrow();
519 predicate(v)
520 })
521 .unwrap_or(false)
522 }
523 }
524
525 fn all<F>(&self, predicate: F) -> impl Fn(Root) -> bool + '_
526 where
527 F: Fn(&V) -> bool + 'static,
528 {
529 move |root: Root| {
530 Readable::get(self, root)
531 .map(|value| {
532 let v: &V = value.borrow();
533 predicate(v)
534 })
535 .unwrap_or(true)
536 }
537 }
538
539 fn count_items<F>(&self, counter: F) -> impl Fn(Root) -> Option<usize> + '_
540 where
541 F: Fn(&V) -> usize + 'static,
542 {
543 move |root: Root| {
544 Readable::get(self, root).map(|value| {
545 let v: &V = value.borrow();
546 counter(v)
547 })
548 }
549 }
550
551 fn find_in<Item, F>(&self, finder: F) -> impl Fn(Root) -> Option<Item> + '_
552 where
553 F: Fn(&V) -> Option<Item> + 'static,
554 {
555 move |root: Root| {
556 Readable::get(self, root).and_then(|value| {
557 let v: &V = value.borrow();
558 finder(v)
559 })
560 }
561 }
562
563 fn take<Output, F>(&self, n: usize, taker: F) -> impl Fn(Root) -> Option<Output> + '_
564 where
565 F: Fn(&V, usize) -> Output + 'static,
566 {
567 move |root: Root| {
568 Readable::get(self, root).map(|value| {
569 let v: &V = value.borrow();
570 taker(v, n)
571 })
572 }
573 }
574
575 fn skip<Output, F>(&self, n: usize, skipper: F) -> impl Fn(Root) -> Option<Output> + '_
576 where
577 F: Fn(&V, usize) -> Output + 'static,
578 {
579 move |root: Root| {
580 Readable::get(self, root).map(|value| {
581 let v: &V = value.borrow();
582 skipper(v, n)
583 })
584 }
585 }
586
587 fn partition_value<Output, F>(&self, partitioner: F) -> impl Fn(Root) -> Option<Output> + '_
588 where
589 F: Fn(&V) -> Output + 'static,
590 {
591 move |root: Root| {
592 Readable::get(self, root).map(|value| {
593 let v: &V = value.borrow();
594 partitioner(v)
595 })
596 }
597 }
598
599 fn min_value<Item, F>(&self, min_fn: F) -> impl Fn(Root) -> Option<Item> + '_
600 where
601 F: Fn(&V) -> Option<Item> + 'static,
602 {
603 move |root: Root| {
604 Readable::get(self, root).and_then(|value| {
605 let v: &V = value.borrow();
606 min_fn(v)
607 })
608 }
609 }
610
611 fn max_value<Item, F>(&self, max_fn: F) -> impl Fn(Root) -> Option<Item> + '_
612 where
613 F: Fn(&V) -> Option<Item> + 'static,
614 {
615 move |root: Root| {
616 Readable::get(self, root).and_then(|value| {
617 let v: &V = value.borrow();
618 max_fn(v)
619 })
620 }
621 }
622
623 fn sum_value<Sum, F>(&self, sum_fn: F) -> impl Fn(Root) -> Option<Sum> + '_
624 where
625 F: Fn(&V) -> Sum + 'static,
626 {
627 move |root: Root| {
628 Readable::get(self, root).map(|value| {
629 let v: &V = value.borrow();
630 sum_fn(v)
631 })
632 }
633 }
634}
635
636impl<R, V, Root, Value, MutRoot, MutValue, G, S> Readable<Root, Value>
637 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
638where
639 Root: std::borrow::Borrow<R>,
640 Value: std::borrow::Borrow<V>,
641 MutRoot: std::borrow::BorrowMut<R>,
642 MutValue: std::borrow::BorrowMut<V>,
643 G: Fn(Root) -> Option<Value>,
644 S: Fn(MutRoot) -> Option<MutValue>,
645{
646 #[inline]
647 fn get(&self, root: Root) -> Option<Value> {
648 (self.get)(root)
649 }
650}
651
652impl<R, V, Root, Value, MutRoot, MutValue, G, S> Writable<MutRoot, MutValue>
653 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
654where
655 Root: std::borrow::Borrow<R>,
656 Value: std::borrow::Borrow<V>,
657 MutRoot: std::borrow::BorrowMut<R>,
658 MutValue: std::borrow::BorrowMut<V>,
659 G: Fn(Root) -> Option<Value>,
660 S: Fn(MutRoot) -> Option<MutValue>,
661{
662 #[inline]
663 fn set(&self, root: MutRoot) -> Option<MutValue> {
664 (self.set)(root)
665 }
666}
667
668impl<R, V, Root, Value, MutRoot, MutValue, G, S> KpTrait<R, V, Root, Value, MutRoot, MutValue>
669 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
670where
671 Root: std::borrow::Borrow<R>,
672 Value: std::borrow::Borrow<V>,
673 MutRoot: std::borrow::BorrowMut<R>,
674 MutValue: std::borrow::BorrowMut<V>,
675 G: Fn(Root) -> Option<Value>,
676 S: Fn(MutRoot) -> Option<MutValue>,
677{
678 fn then<SV, SubValue, MutSubValue, Next>(
679 self,
680 next: Next,
681 ) -> impl KeyPath<Root, SubValue, MutRoot, MutSubValue>
682 where
683 SubValue: std::borrow::Borrow<SV>,
684 MutSubValue: std::borrow::BorrowMut<SV>,
685 Next: Readable<Value, SubValue> + Writable<MutValue, MutSubValue> + Clone,
686 {
687 let first_get = self.get;
688 let first_set = self.set;
689 let next_get = next.clone();
690 let next_set = next;
691
692 Kp::new(
693 move |root: Root| {
694 first_get(root).and_then(|value| Readable::get(&next_get, value))
695 },
696 move |root: MutRoot| {
697 first_set(root).and_then(|value| Writable::set(&next_set, value))
698 },
699 )
700 }
701}
702
703impl<R, V, Root, Value, MutRoot, MutValue, G, S>
704 CoercionTrait<R, V, Root, Value, MutRoot, MutValue, G, S>
705 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
706where
707 Root: std::borrow::Borrow<R>,
708 Value: std::borrow::Borrow<V>,
709 MutRoot: std::borrow::BorrowMut<R>,
710 MutValue: std::borrow::BorrowMut<V>,
711 G: Fn(Root) -> Option<Value>,
712 S: Fn(MutRoot) -> Option<MutValue>,
713{
714 fn for_arc<'b>(
715 &self,
716 ) -> Kp<
717 std::sync::Arc<R>,
718 V,
719 std::sync::Arc<R>,
720 Value,
721 std::sync::Arc<R>,
722 MutValue,
723 impl Fn(std::sync::Arc<R>) -> Option<Value>,
724 impl Fn(std::sync::Arc<R>) -> Option<MutValue>,
725 >
726 where
727 R: 'b,
728 V: 'b,
729 Root: for<'a> From<&'a R>,
730 MutRoot: for<'a> From<&'a mut R>,
731 {
732 Kp::new(
733 move |arc_root: std::sync::Arc<R>| {
734 let r_ref: &R = &*arc_root;
735 (self.get)(Root::from(r_ref))
736 },
737 move |mut arc_root: std::sync::Arc<R>| {
738 std::sync::Arc::get_mut(&mut arc_root)
739 .and_then(|r_mut| (self.set)(MutRoot::from(r_mut)))
740 },
741 )
742 }
743
744 fn for_box<'a>(
745 &self,
746 ) -> Kp<
747 Box<R>,
748 V,
749 Box<R>,
750 Value,
751 Box<R>,
752 MutValue,
753 impl Fn(Box<R>) -> Option<Value>,
754 impl Fn(Box<R>) -> Option<MutValue>,
755 >
756 where
757 R: 'a,
758 V: 'a,
759 Root: for<'b> From<&'b R>,
760 MutRoot: for<'b> From<&'b mut R>,
761 {
762 Kp::new(
763 move |r: Box<R>| {
764 let r_ref: &R = r.as_ref();
765 (self.get)(Root::from(r_ref))
766 },
767 move |mut r: Box<R>| (self.set)(MutRoot::from(r.as_mut())),
768 )
769 }
770
771 #[inline]
772 fn into_set(self) -> impl Fn(MutRoot) -> Option<MutValue> {
773 self.set
774 }
775
776 #[inline]
777 fn into_get(self) -> impl Fn(Root) -> Option<Value> {
778 self.get
779 }
780}
781
782impl<R, V, Root, Value, MutRoot, MutValue, G, S>
783 HofTrait<R, V, Root, Value, MutRoot, MutValue, G, S>
784 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
785where
786 Root: std::borrow::Borrow<R>,
787 Value: std::borrow::Borrow<V>,
788 MutRoot: std::borrow::BorrowMut<R>,
789 MutValue: std::borrow::BorrowMut<V>,
790 G: Fn(Root) -> Option<Value>,
791 S: Fn(MutRoot) -> Option<MutValue>,
792{
793}
794
795impl<R, V, Root, Value, MutRoot, MutValue, G, S> AccessorTrait<Root, Value, MutRoot, MutValue>
796 for Kp<R, V, Root, Value, MutRoot, MutValue, G, S>
797where
798 Root: std::borrow::Borrow<R>,
799 Value: std::borrow::Borrow<V>,
800 MutRoot: std::borrow::BorrowMut<R>,
801 MutValue: std::borrow::BorrowMut<V>,
802 G: Fn(Root) -> Option<Value>,
803 S: Fn(MutRoot) -> Option<MutValue>,
804{
805}