surrealdb_expr/expr/convert/
part.rs1use crate::sql::part::*;
7
8impl From<Part> for crate::expr::Part {
9 fn from(v: Part) -> Self {
10 match v {
11 Part::All => Self::All,
12 Part::Flatten => Self::Flatten,
13 Part::Last => Self::Last,
14 Part::First => Self::First,
15 Part::Field(ident) => Self::Field(ident),
16 Part::Where(value) => Self::Where(value.into()),
17 Part::Graph(graph) => Self::Lookup(Box::new((*graph).into())),
18 Part::Value(value) => Self::Value(value.into()),
19 Part::Start(value) => Self::Start(value.into()),
20 Part::Method(method, values) => {
21 Self::Method(method, values.into_iter().map(Into::into).collect())
22 }
23 Part::Destructure(parts) => {
24 Self::Destructure(parts.into_iter().map(Into::into).collect())
25 }
26 Part::Optional => Self::Optional,
27 Part::Recurse(recurse, idiom, instructions) => {
28 let idiom = idiom.map(|idiom| idiom.into());
29 let instructions = instructions.map(Into::into);
30 crate::expr::Part::Recurse(recurse.into(), idiom, instructions)
31 }
32 Part::Doc => crate::expr::Part::Doc,
33 Part::RepeatRecurse => crate::expr::Part::RepeatRecurse,
34 }
35 }
36}
37
38impl From<crate::expr::Part> for Part {
39 fn from(v: crate::expr::Part) -> Self {
40 match v {
41 crate::expr::Part::All => Self::All,
42 crate::expr::Part::Flatten => Self::Flatten,
43 crate::expr::Part::Last => Self::Last,
44 crate::expr::Part::First => Self::First,
45 crate::expr::Part::Field(ident) => Self::Field(ident),
46 crate::expr::Part::Where(value) => Self::Where(value.into()),
47 crate::expr::Part::Lookup(graph) => Self::Graph(Box::new((*graph).into())),
48 crate::expr::Part::Value(value) => Self::Value(value.into()),
49 crate::expr::Part::Start(value) => Self::Start(value.into()),
50 crate::expr::Part::Method(method, values) => {
51 Self::Method(method, values.into_iter().map(Into::into).collect())
52 }
53 crate::expr::Part::Destructure(parts) => {
54 Self::Destructure(parts.into_iter().map(Into::<DestructurePart>::into).collect())
55 }
56 crate::expr::Part::Optional => Self::Optional,
57 crate::expr::Part::Recurse(recurse, idiom, instructions) => Self::Recurse(
58 recurse.into(),
59 idiom.map(|idiom| idiom.into()),
60 instructions.map(Into::into),
61 ),
62 crate::expr::Part::Doc => Self::Doc,
63 crate::expr::Part::RepeatRecurse => Self::RepeatRecurse,
64 }
65 }
66}
67
68impl From<DestructurePart> for crate::expr::part::DestructurePart {
69 fn from(v: DestructurePart) -> Self {
70 match v {
71 DestructurePart::All(v) => Self::All(v),
72 DestructurePart::Field(v) => Self::Field(v),
73 DestructurePart::Aliased(v, idiom) => Self::Aliased(v, idiom.into()),
74 DestructurePart::Destructure(v, d) => {
75 Self::Destructure(v, d.into_iter().map(Into::into).collect())
76 }
77 }
78 }
79}
80
81impl From<crate::expr::part::DestructurePart> for DestructurePart {
82 fn from(v: crate::expr::part::DestructurePart) -> Self {
83 match v {
84 crate::expr::part::DestructurePart::All(v) => Self::All(v),
85 crate::expr::part::DestructurePart::Field(v) => Self::Field(v),
86 crate::expr::part::DestructurePart::Aliased(v, idiom) => Self::Aliased(v, idiom.into()),
87 crate::expr::part::DestructurePart::Destructure(v, d) => {
88 Self::Destructure(v, d.into_iter().map(Into::<DestructurePart>::into).collect())
89 }
90 }
91 }
92}
93
94impl From<Recurse> for crate::expr::part::Recurse {
95 fn from(v: Recurse) -> Self {
96 match v {
97 Recurse::Fixed(v) => Self::Fixed(v),
98 Recurse::Range(min, max) => Self::Range(min, max),
99 }
100 }
101}
102
103impl From<crate::expr::part::Recurse> for Recurse {
104 fn from(v: crate::expr::part::Recurse) -> Self {
105 match v {
106 crate::expr::part::Recurse::Fixed(v) => Self::Fixed(v),
107 crate::expr::part::Recurse::Range(min, max) => Self::Range(min, max),
108 }
109 }
110}
111
112impl From<RecurseInstruction> for crate::expr::part::RecurseInstruction {
113 fn from(v: RecurseInstruction) -> Self {
114 match v {
115 RecurseInstruction::Path {
116 inclusive,
117 } => Self::Path {
118 inclusive,
119 },
120 RecurseInstruction::Collect {
121 inclusive,
122 } => Self::Collect {
123 inclusive,
124 },
125 RecurseInstruction::Shortest {
126 expects,
127 inclusive,
128 } => Self::Shortest {
129 expects: expects.into(),
130 inclusive,
131 },
132 }
133 }
134}
135
136impl From<crate::expr::part::RecurseInstruction> for RecurseInstruction {
137 fn from(v: crate::expr::part::RecurseInstruction) -> Self {
138 match v {
139 crate::expr::part::RecurseInstruction::Path {
140 inclusive,
141 } => Self::Path {
142 inclusive,
143 },
144 crate::expr::part::RecurseInstruction::Collect {
145 inclusive,
146 } => Self::Collect {
147 inclusive,
148 },
149 crate::expr::part::RecurseInstruction::Shortest {
150 expects,
151 inclusive,
152 } => Self::Shortest {
153 expects: expects.into(),
154 inclusive,
155 },
156 }
157 }
158}