Skip to main content

zenoh_keyexpr/keyexpr_tree/traits/
default_impls.rs

1//
2// Copyright (c) 2023 ZettaScale Technology
3//
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// http://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
7// which is available at https://www.apache.org/licenses/LICENSE-2.0.
8//
9// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
10//
11// Contributors:
12//   ZettaScale Zenoh Team, <zenoh@zettascale.tech>
13//
14
15use alloc::{boxed::Box, sync::Arc};
16
17use token_cell::prelude::{TokenCell, TokenCellTrait, TokenTrait};
18
19use super::*;
20
21impl<T: HasChunk> HasChunk for &T {
22    fn chunk(&self) -> &keyexpr {
23        T::chunk(self)
24    }
25}
26impl<T: HasChunk> HasChunk for &mut T {
27    fn chunk(&self) -> &keyexpr {
28        T::chunk(self)
29    }
30}
31impl<T: HasChunk> HasChunk for Box<T> {
32    fn chunk(&self) -> &keyexpr {
33        T::chunk(self)
34    }
35}
36impl<T: HasChunk> HasChunk for Arc<T> {
37    fn chunk(&self) -> &keyexpr {
38        T::chunk(self)
39    }
40}
41impl<T: HasChunk, Token: TokenTrait> HasChunk for TokenCell<T, Token> {
42    fn chunk(&self) -> &keyexpr {
43        // SAFETY: upheld by the surrounding invariants and prior validation.
44        T::chunk(unsafe { &*self.get() })
45    }
46}
47impl<T> AsNode<T> for T {
48    fn as_node(&self) -> &T {
49        self
50    }
51}
52impl<T> AsNode<T> for &T {
53    fn as_node(&self) -> &T {
54        self
55    }
56}
57impl<T> AsNode<T> for &mut T {
58    fn as_node(&self) -> &T {
59        self
60    }
61}
62impl<T> AsNodeMut<T> for T {
63    fn as_node_mut(&mut self) -> &mut T {
64        self
65    }
66}
67impl<T> AsNodeMut<T> for &mut T {
68    fn as_node_mut(&mut self) -> &mut T {
69        self
70    }
71}
72impl<T: IKeyExprTreeNode<Weight>, Weight> IKeyExprTreeNode<Weight> for &T {}
73impl<T: IKeyExprTreeNode<Weight>, Weight> UIKeyExprTreeNode<Weight> for &T {
74    type Parent = T::Parent;
75    /// # Safety
76    /// Callers must uphold the invariants required by this unsafe API.
77    unsafe fn __parent(&self) -> Option<&Self::Parent> {
78        T::parent(self)
79    }
80    /// # Safety
81    /// Callers must uphold the invariants required by this unsafe API.
82    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
83        T::keyexpr(self)
84    }
85    /// # Safety
86    /// Callers must uphold the invariants required by this unsafe API.
87    unsafe fn __weight(&self) -> Option<&Weight> {
88        T::weight(self)
89    }
90
91    type Child = T::Child;
92    type Children = T::Children;
93
94    /// # Safety
95    /// Callers must uphold the invariants required by this unsafe API.
96    unsafe fn __children(&self) -> &Self::Children {
97        T::children(self)
98    }
99}
100impl<T: IKeyExprTreeNode<Weight>, Weight> IKeyExprTreeNode<Weight> for &mut T {}
101impl<T: IKeyExprTreeNode<Weight>, Weight> UIKeyExprTreeNode<Weight> for &mut T {
102    type Parent = T::Parent;
103    /// # Safety
104    /// Callers must uphold the invariants required by this unsafe API.
105    unsafe fn __parent(&self) -> Option<&Self::Parent> {
106        T::parent(self)
107    }
108    /// # Safety
109    /// Callers must uphold the invariants required by this unsafe API.
110    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
111        T::keyexpr(self)
112    }
113    /// # Safety
114    /// Callers must uphold the invariants required by this unsafe API.
115    unsafe fn __weight(&self) -> Option<&Weight> {
116        T::weight(self)
117    }
118
119    type Child = T::Child;
120    type Children = T::Children;
121
122    /// # Safety
123    /// Callers must uphold the invariants required by this unsafe API.
124    unsafe fn __children(&self) -> &Self::Children {
125        T::children(self)
126    }
127}
128impl<T: IKeyExprTreeNode<Weight>, Weight> IKeyExprTreeNode<Weight> for Box<T> {}
129impl<T: IKeyExprTreeNode<Weight>, Weight> UIKeyExprTreeNode<Weight> for Box<T> {
130    type Parent = T::Parent;
131    /// # Safety
132    /// Callers must uphold the invariants required by this unsafe API.
133    unsafe fn __parent(&self) -> Option<&Self::Parent> {
134        T::parent(self)
135    }
136    /// # Safety
137    /// Callers must uphold the invariants required by this unsafe API.
138    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
139        T::keyexpr(self)
140    }
141    /// # Safety
142    /// Callers must uphold the invariants required by this unsafe API.
143    unsafe fn __weight(&self) -> Option<&Weight> {
144        T::weight(self)
145    }
146
147    type Child = T::Child;
148    type Children = T::Children;
149
150    /// # Safety
151    /// Callers must uphold the invariants required by this unsafe API.
152    unsafe fn __children(&self) -> &Self::Children {
153        T::children(self)
154    }
155}
156
157impl<T: IKeyExprTreeNodeMut<Weight>, Weight> IKeyExprTreeNodeMut<Weight> for &mut T {
158    fn parent_mut(&mut self) -> Option<&mut Self::Parent> {
159        T::parent_mut(self)
160    }
161    fn weight_mut(&mut self) -> Option<&mut Weight> {
162        T::weight_mut(self)
163    }
164    fn take_weight(&mut self) -> Option<Weight> {
165        T::take_weight(self)
166    }
167    fn insert_weight(&mut self, weight: Weight) -> Option<Weight> {
168        T::insert_weight(self, weight)
169    }
170
171    fn children_mut(&mut self) -> &mut Self::Children {
172        T::children_mut(self)
173    }
174}
175
176impl<T: IKeyExprTreeNodeMut<Weight>, Weight> IKeyExprTreeNodeMut<Weight> for Box<T> {
177    fn parent_mut(&mut self) -> Option<&mut Self::Parent> {
178        T::parent_mut(self)
179    }
180    fn weight_mut(&mut self) -> Option<&mut Weight> {
181        T::weight_mut(self)
182    }
183    fn take_weight(&mut self) -> Option<Weight> {
184        T::take_weight(self)
185    }
186    fn insert_weight(&mut self, weight: Weight) -> Option<Weight> {
187        T::insert_weight(self, weight)
188    }
189
190    fn children_mut(&mut self) -> &mut Self::Children {
191        T::children_mut(self)
192    }
193}
194
195impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
196    for (&TokenCell<T, Token>, &Token)
197{
198}
199impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
200    for (&TokenCell<T, Token>, &Token)
201{
202    type Parent = T::Parent;
203    /// # Safety
204    /// Callers must uphold the invariants required by this unsafe API.
205    unsafe fn __parent(&self) -> Option<&Self::Parent> {
206        self.0
207            .try_borrow(self.1)
208            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
209            .parent()
210    }
211    /// # Safety
212    /// Callers must uphold the invariants required by this unsafe API.
213    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
214        self.0
215            .try_borrow(self.1)
216            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
217            .keyexpr()
218    }
219    /// # Safety
220    /// Callers must uphold the invariants required by this unsafe API.
221    unsafe fn __weight(&self) -> Option<&Weight> {
222        self.0
223            .try_borrow(self.1)
224            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
225            .weight()
226    }
227
228    type Child = T::Child;
229    type Children = T::Children;
230
231    /// # Safety
232    /// Callers must uphold the invariants required by this unsafe API.
233    unsafe fn __children(&self) -> &Self::Children {
234        self.0
235            .try_borrow(self.1)
236            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
237            .children()
238    }
239}
240
241impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
242    for (&TokenCell<T, Token>, &mut Token)
243{
244}
245impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
246    for (&TokenCell<T, Token>, &mut Token)
247{
248    type Parent = T::Parent;
249    /// # Safety
250    /// Callers must uphold the invariants required by this unsafe API.
251    unsafe fn __parent(&self) -> Option<&Self::Parent> {
252        self.0
253            .try_borrow(self.1)
254            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
255            .parent()
256    }
257    /// # Safety
258    /// Callers must uphold the invariants required by this unsafe API.
259    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
260        self.0
261            .try_borrow(self.1)
262            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
263            .keyexpr()
264    }
265    /// # Safety
266    /// Callers must uphold the invariants required by this unsafe API.
267    unsafe fn __weight(&self) -> Option<&Weight> {
268        self.0
269            .try_borrow(self.1)
270            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
271            .weight()
272    }
273
274    type Child = T::Child;
275    type Children = T::Children;
276
277    /// # Safety
278    /// Callers must uphold the invariants required by this unsafe API.
279    unsafe fn __children(&self) -> &Self::Children {
280        self.0
281            .try_borrow(self.1)
282            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
283            .children()
284    }
285}
286
287impl<T: IKeyExprTreeNodeMut<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNodeMut<Weight>
288    for (&TokenCell<T, Token>, &mut Token)
289{
290    fn parent_mut(&mut self) -> Option<&mut Self::Parent> {
291        self.0
292            .try_borrow_mut(self.1)
293            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
294            .parent_mut()
295    }
296    fn weight_mut(&mut self) -> Option<&mut Weight> {
297        self.0
298            .try_borrow_mut(self.1)
299            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
300            .weight_mut()
301    }
302    fn take_weight(&mut self) -> Option<Weight> {
303        self.0
304            .try_borrow_mut(self.1)
305            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
306            .take_weight()
307    }
308    fn insert_weight(&mut self, weight: Weight) -> Option<Weight> {
309        self.0
310            .try_borrow_mut(self.1)
311            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
312            .insert_weight(weight)
313    }
314
315    fn children_mut(&mut self) -> &mut Self::Children {
316        self.0
317            .try_borrow_mut(self.1)
318            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
319            .children_mut()
320    }
321}
322
323impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
324    for (&Arc<TokenCell<T, Token>>, &Token)
325{
326}
327impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
328    for (&Arc<TokenCell<T, Token>>, &Token)
329{
330    type Parent = T::Parent;
331    /// # Safety
332    /// Callers must uphold the invariants required by this unsafe API.
333    unsafe fn __parent(&self) -> Option<&Self::Parent> {
334        self.0
335            .try_borrow(self.1)
336            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
337            .parent()
338    }
339    /// # Safety
340    /// Callers must uphold the invariants required by this unsafe API.
341    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
342        self.0
343            .try_borrow(self.1)
344            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
345            .keyexpr()
346    }
347    /// # Safety
348    /// Callers must uphold the invariants required by this unsafe API.
349    unsafe fn __weight(&self) -> Option<&Weight> {
350        self.0
351            .try_borrow(self.1)
352            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
353            .weight()
354    }
355
356    type Child = T::Child;
357    type Children = T::Children;
358
359    /// # Safety
360    /// Callers must uphold the invariants required by this unsafe API.
361    unsafe fn __children(&self) -> &Self::Children {
362        self.0
363            .try_borrow(self.1)
364            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
365            .children()
366    }
367}
368
369impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
370    for (&Arc<TokenCell<T, Token>>, &mut Token)
371{
372}
373impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
374    for (&Arc<TokenCell<T, Token>>, &mut Token)
375{
376    type Parent = T::Parent;
377    /// # Safety
378    /// Callers must uphold the invariants required by this unsafe API.
379    unsafe fn __parent(&self) -> Option<&Self::Parent> {
380        self.0
381            .try_borrow(self.1)
382            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
383            .parent()
384    }
385    /// # Safety
386    /// Callers must uphold the invariants required by this unsafe API.
387    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
388        self.0
389            .try_borrow(self.1)
390            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
391            .keyexpr()
392    }
393    /// # Safety
394    /// Callers must uphold the invariants required by this unsafe API.
395    unsafe fn __weight(&self) -> Option<&Weight> {
396        self.0
397            .try_borrow(self.1)
398            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
399            .weight()
400    }
401
402    type Child = T::Child;
403    type Children = T::Children;
404
405    /// # Safety
406    /// Callers must uphold the invariants required by this unsafe API.
407    unsafe fn __children(&self) -> &Self::Children {
408        self.0
409            .try_borrow(self.1)
410            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
411            .children()
412    }
413}
414
415impl<T: IKeyExprTreeNodeMut<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNodeMut<Weight>
416    for (&Arc<TokenCell<T, Token>>, &mut Token)
417{
418    fn parent_mut(&mut self) -> Option<&mut Self::Parent> {
419        self.0
420            .try_borrow_mut(self.1)
421            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
422            .parent_mut()
423    }
424    fn weight_mut(&mut self) -> Option<&mut Weight> {
425        self.0
426            .try_borrow_mut(self.1)
427            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
428            .weight_mut()
429    }
430    fn take_weight(&mut self) -> Option<Weight> {
431        self.0
432            .try_borrow_mut(self.1)
433            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
434            .take_weight()
435    }
436    fn insert_weight(&mut self, weight: Weight) -> Option<Weight> {
437        self.0
438            .try_borrow_mut(self.1)
439            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
440            .insert_weight(weight)
441    }
442
443    fn children_mut(&mut self) -> &mut Self::Children {
444        self.0
445            .try_borrow_mut(self.1)
446            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
447            .children_mut()
448    }
449}
450
451use crate::keyexpr_tree::arc_tree::Tokenized;
452impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
453    for Tokenized<&TokenCell<T, Token>, &Token>
454{
455}
456impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
457    for Tokenized<&TokenCell<T, Token>, &Token>
458{
459    type Parent = T::Parent;
460    /// # Safety
461    /// Callers must uphold the invariants required by this unsafe API.
462    unsafe fn __parent(&self) -> Option<&Self::Parent> {
463        self.0
464            .try_borrow(self.1)
465            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
466            .parent()
467    }
468    /// # Safety
469    /// Callers must uphold the invariants required by this unsafe API.
470    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
471        self.0
472            .try_borrow(self.1)
473            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
474            .keyexpr()
475    }
476    /// # Safety
477    /// Callers must uphold the invariants required by this unsafe API.
478    unsafe fn __weight(&self) -> Option<&Weight> {
479        self.0
480            .try_borrow(self.1)
481            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
482            .weight()
483    }
484
485    type Child = T::Child;
486    type Children = T::Children;
487
488    /// # Safety
489    /// Callers must uphold the invariants required by this unsafe API.
490    unsafe fn __children(&self) -> &Self::Children {
491        self.0
492            .try_borrow(self.1)
493            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
494            .children()
495    }
496}
497
498impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
499    for Tokenized<&TokenCell<T, Token>, &mut Token>
500{
501}
502impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
503    for Tokenized<&TokenCell<T, Token>, &mut Token>
504{
505    type Parent = T::Parent;
506    /// # Safety
507    /// Callers must uphold the invariants required by this unsafe API.
508    unsafe fn __parent(&self) -> Option<&Self::Parent> {
509        self.0
510            .try_borrow(self.1)
511            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
512            .parent()
513    }
514    /// # Safety
515    /// Callers must uphold the invariants required by this unsafe API.
516    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
517        self.0
518            .try_borrow(self.1)
519            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
520            .keyexpr()
521    }
522    /// # Safety
523    /// Callers must uphold the invariants required by this unsafe API.
524    unsafe fn __weight(&self) -> Option<&Weight> {
525        self.0
526            .try_borrow(self.1)
527            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
528            .weight()
529    }
530
531    type Child = T::Child;
532    type Children = T::Children;
533
534    /// # Safety
535    /// Callers must uphold the invariants required by this unsafe API.
536    unsafe fn __children(&self) -> &Self::Children {
537        self.0
538            .try_borrow(self.1)
539            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
540            .children()
541    }
542}
543
544impl<T: IKeyExprTreeNodeMut<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNodeMut<Weight>
545    for Tokenized<&TokenCell<T, Token>, &mut Token>
546{
547    fn parent_mut(&mut self) -> Option<&mut Self::Parent> {
548        self.0
549            .try_borrow_mut(self.1)
550            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
551            .parent_mut()
552    }
553    fn weight_mut(&mut self) -> Option<&mut Weight> {
554        self.0
555            .try_borrow_mut(self.1)
556            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
557            .weight_mut()
558    }
559    fn take_weight(&mut self) -> Option<Weight> {
560        self.0
561            .try_borrow_mut(self.1)
562            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
563            .take_weight()
564    }
565    fn insert_weight(&mut self, weight: Weight) -> Option<Weight> {
566        self.0
567            .try_borrow_mut(self.1)
568            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
569            .insert_weight(weight)
570    }
571
572    fn children_mut(&mut self) -> &mut Self::Children {
573        self.0
574            .try_borrow_mut(self.1)
575            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
576            .children_mut()
577    }
578}
579
580impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
581    for Tokenized<&Arc<TokenCell<T, Token>>, &Token>
582{
583}
584impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
585    for Tokenized<&Arc<TokenCell<T, Token>>, &Token>
586{
587    type Parent = T::Parent;
588    /// # Safety
589    /// Callers must uphold the invariants required by this unsafe API.
590    unsafe fn __parent(&self) -> Option<&Self::Parent> {
591        self.0
592            .try_borrow(self.1)
593            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
594            .parent()
595    }
596    /// # Safety
597    /// Callers must uphold the invariants required by this unsafe API.
598    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
599        self.0
600            .try_borrow(self.1)
601            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
602            .keyexpr()
603    }
604    /// # Safety
605    /// Callers must uphold the invariants required by this unsafe API.
606    unsafe fn __weight(&self) -> Option<&Weight> {
607        self.0
608            .try_borrow(self.1)
609            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
610            .weight()
611    }
612
613    type Child = T::Child;
614    type Children = T::Children;
615
616    /// # Safety
617    /// Callers must uphold the invariants required by this unsafe API.
618    unsafe fn __children(&self) -> &Self::Children {
619        self.0
620            .try_borrow(self.1)
621            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
622            .children()
623    }
624}
625
626impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNode<Weight>
627    for Tokenized<&Arc<TokenCell<T, Token>>, &mut Token>
628{
629}
630impl<T: IKeyExprTreeNode<Weight>, Weight, Token: TokenTrait> UIKeyExprTreeNode<Weight>
631    for Tokenized<&Arc<TokenCell<T, Token>>, &mut Token>
632{
633    type Parent = T::Parent;
634    /// # Safety
635    /// Callers must uphold the invariants required by this unsafe API.
636    unsafe fn __parent(&self) -> Option<&Self::Parent> {
637        self.0
638            .try_borrow(self.1)
639            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
640            .parent()
641    }
642    /// # Safety
643    /// Callers must uphold the invariants required by this unsafe API.
644    unsafe fn __keyexpr(&self) -> OwnedKeyExpr {
645        self.0
646            .try_borrow(self.1)
647            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
648            .keyexpr()
649    }
650    /// # Safety
651    /// Callers must uphold the invariants required by this unsafe API.
652    unsafe fn __weight(&self) -> Option<&Weight> {
653        self.0
654            .try_borrow(self.1)
655            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
656            .weight()
657    }
658
659    type Child = T::Child;
660    type Children = T::Children;
661
662    /// # Safety
663    /// Callers must uphold the invariants required by this unsafe API.
664    unsafe fn __children(&self) -> &Self::Children {
665        self.0
666            .try_borrow(self.1)
667            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
668            .children()
669    }
670}
671
672impl<T: IKeyExprTreeNodeMut<Weight>, Weight, Token: TokenTrait> IKeyExprTreeNodeMut<Weight>
673    for Tokenized<&Arc<TokenCell<T, Token>>, &mut Token>
674{
675    fn parent_mut(&mut self) -> Option<&mut Self::Parent> {
676        self.0
677            .try_borrow_mut(self.1)
678            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
679            .parent_mut()
680    }
681    fn weight_mut(&mut self) -> Option<&mut Weight> {
682        self.0
683            .try_borrow_mut(self.1)
684            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
685            .weight_mut()
686    }
687    fn take_weight(&mut self) -> Option<Weight> {
688        self.0
689            .try_borrow_mut(self.1)
690            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
691            .take_weight()
692    }
693    fn insert_weight(&mut self, weight: Weight) -> Option<Weight> {
694        self.0
695            .try_borrow_mut(self.1)
696            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
697            .insert_weight(weight)
698    }
699
700    fn children_mut(&mut self) -> &mut Self::Children {
701        self.0
702            .try_borrow_mut(self.1)
703            .unwrap_or_else(|_| panic!("Used wrong token to access TokenCell"))
704            .children_mut()
705    }
706}