moduforge_model/ops/
mod.rs

1use crate::tree::Tree;
2
3pub mod add;
4pub mod bitand;
5pub mod bitor;
6pub mod mul;
7pub mod shl;
8pub mod shr;
9pub mod sub;
10
11// 用于处理节点赋值的包装器
12pub struct NodeRef<'a> {
13    tree: &'a mut Tree,
14    key: String,
15}
16
17impl<'a> NodeRef<'a> {
18    pub fn new(
19        tree: &'a mut Tree,
20        key: String,
21    ) -> Self {
22        Self { tree, key }
23    }
24}
25
26impl<'a> std::ops::Deref for NodeRef<'a> {
27    type Target = Tree;
28
29    fn deref(&self) -> &Self::Target {
30        self.tree
31    }
32}
33
34impl<'a> std::ops::DerefMut for NodeRef<'a> {
35    fn deref_mut(&mut self) -> &mut Self::Target {
36        self.tree
37    }
38}
39
40// 用于处理节点赋值的包装器
41pub struct MarkRef<'a> {
42    tree: &'a mut Tree,
43    key: String,
44}
45
46impl<'a> MarkRef<'a> {
47    pub fn new(
48        tree: &'a mut Tree,
49        key: String,
50    ) -> Self {
51        Self { tree, key }
52    }
53}
54
55impl<'a> std::ops::Deref for MarkRef<'a> {
56    type Target = Tree;
57
58    fn deref(&self) -> &Self::Target {
59        self.tree
60    }
61}
62
63impl<'a> std::ops::DerefMut for MarkRef<'a> {
64    fn deref_mut(&mut self) -> &mut Self::Target {
65        self.tree
66    }
67}
68
69pub struct AttrsRef<'a> {
70    tree: &'a mut Tree,
71    key: String,
72}
73
74impl<'a> AttrsRef<'a> {
75    pub fn new(
76        tree: &'a mut Tree,
77        key: String,
78    ) -> Self {
79        Self { tree, key }
80    }
81}
82
83impl<'a> std::ops::Deref for AttrsRef<'a> {
84    type Target = Tree;
85
86    fn deref(&self) -> &Self::Target {
87        self.tree
88    }
89}
90
91impl<'a> std::ops::DerefMut for AttrsRef<'a> {
92    fn deref_mut(&mut self) -> &mut Self::Target {
93        self.tree
94    }
95}