cel_cxx_ffi/common/
expr.rs1use crate::absl::{MutSpanElement, SpanElement, StringView};
2use crate::common::Constant;
3use std::pin::Pin;
4
5#[cxx::bridge]
6mod ffi {
7 #[namespace = "absl"]
8 unsafe extern "C++" {
9 include!(<absl/strings/string_view.h>);
10 type string_view<'a> = super::StringView<'a>;
11 }
12
13 #[namespace = "cel"]
14 unsafe extern "C++" {
15 include!(<common/expr.h>);
16 type Constant = super::Constant;
17 type ExprKindCase = super::ExprKindCase;
18 type Expr;
19
20 fn id(self: &Expr) -> i64;
21 fn set_id(self: Pin<&mut Expr>, id: i64);
22 fn kind_case(self: &Expr) -> ExprKindCase;
23
24 fn has_const_expr(self: &Expr) -> bool;
25 fn const_expr(self: &Expr) -> &Constant;
26 #[rust_name = "const_expr_mut"]
27 fn mutable_const_expr(self: Pin<&mut Expr>) -> Pin<&mut Constant>;
28
29 fn has_ident_expr(self: &Expr) -> bool;
30 fn ident_expr(self: &Expr) -> &IdentExpr;
31 #[rust_name = "ident_expr_mut"]
32 fn mutable_ident_expr(self: Pin<&mut Expr>) -> Pin<&mut IdentExpr>;
33
34 fn has_select_expr(self: &Expr) -> bool;
35 fn select_expr(self: &Expr) -> &SelectExpr;
36 #[rust_name = "select_expr_mut"]
37 fn mutable_select_expr(self: Pin<&mut Expr>) -> Pin<&mut SelectExpr>;
38
39 fn has_call_expr(self: &Expr) -> bool;
40 fn call_expr(self: &Expr) -> &CallExpr;
41 #[rust_name = "call_expr_mut"]
42 fn mutable_call_expr(self: Pin<&mut Expr>) -> Pin<&mut CallExpr>;
43
44 fn has_list_expr(self: &Expr) -> bool;
45 fn list_expr(self: &Expr) -> &ListExpr;
46 #[rust_name = "list_expr_mut"]
47 fn mutable_list_expr(self: Pin<&mut Expr>) -> Pin<&mut ListExpr>;
48
49 fn has_struct_expr(self: &Expr) -> bool;
50 fn struct_expr(self: &Expr) -> &StructExpr;
51 #[rust_name = "struct_expr_mut"]
52 fn mutable_struct_expr(self: Pin<&mut Expr>) -> Pin<&mut StructExpr>;
53
54 fn has_map_expr(self: &Expr) -> bool;
55 fn map_expr(self: &Expr) -> &MapExpr;
56 #[rust_name = "map_expr_mut"]
57 fn mutable_map_expr(self: Pin<&mut Expr>) -> Pin<&mut MapExpr>;
58
59 fn has_comprehension_expr(self: &Expr) -> bool;
60 fn comprehension_expr(self: &Expr) -> &ComprehensionExpr;
61 #[rust_name = "comprehension_expr_mut"]
62 fn mutable_comprehension_expr(self: Pin<&mut Expr>) -> Pin<&mut ComprehensionExpr>;
63
64 type UnspecifiedExpr;
65 type IdentExpr;
66 fn name(self: &IdentExpr) -> &CxxString;
67 fn set_name<'a>(self: Pin<&mut IdentExpr>, name: string_view<'a>);
68
69 type SelectExpr;
70 fn has_operand(self: &SelectExpr) -> bool;
71 fn operand(self: &SelectExpr) -> &Expr;
72 #[rust_name = "operand_mut"]
73 fn mutable_operand(self: Pin<&mut SelectExpr>) -> Pin<&mut Expr>;
74 fn set_operand(self: Pin<&mut SelectExpr>, operand: UniquePtr<Expr>);
75 fn release_operand(self: Pin<&mut SelectExpr>) -> UniquePtr<Expr>;
76
77 fn field(self: &SelectExpr) -> &CxxString;
78 fn set_field<'a>(self: Pin<&mut SelectExpr>, field: string_view<'a>);
79
80 fn test_only(self: &SelectExpr) -> bool;
81 fn set_test_only(self: Pin<&mut SelectExpr>, test_only: bool);
82
83 type CallExpr;
84 fn function(self: &CallExpr) -> &CxxString;
85 fn set_function<'a>(self: Pin<&mut CallExpr>, function: string_view<'a>);
86
87 fn has_target(self: &CallExpr) -> bool;
88 fn target(self: &CallExpr) -> &Expr;
89 #[rust_name = "target_mut"]
90 fn mutable_target(self: Pin<&mut CallExpr>) -> Pin<&mut Expr>;
91 fn set_target(self: Pin<&mut CallExpr>, target: UniquePtr<Expr>);
92 fn release_target(self: Pin<&mut CallExpr>) -> UniquePtr<Expr>;
93
94 fn args(self: &CallExpr) -> &CxxVector<Expr>;
95 #[rust_name = "args_mut"]
96 fn mutable_args(self: Pin<&mut CallExpr>) -> Pin<&mut CxxVector<Expr>>;
97 fn add_args(self: Pin<&mut CallExpr>) -> Pin<&mut Expr>;
98
99 type ListExprElement;
100 fn has_expr(self: &ListExprElement) -> bool;
101 fn expr(self: &ListExprElement) -> &Expr;
102 #[rust_name = "expr_mut"]
103 fn mutable_expr(self: Pin<&mut ListExprElement>) -> Pin<&mut Expr>;
104 fn set_expr(self: Pin<&mut ListExprElement>, expr: UniquePtr<Expr>);
105
106 fn optional(self: &ListExprElement) -> bool;
107 fn set_optional(self: Pin<&mut ListExprElement>, optional: bool);
108
109 type ListExpr;
110 fn elements(self: &ListExpr) -> &CxxVector<ListExprElement>;
111 #[rust_name = "elements_mut"]
112 fn mutable_elements(self: Pin<&mut ListExpr>) -> Pin<&mut CxxVector<ListExprElement>>;
113 fn add_elements(self: Pin<&mut ListExpr>) -> Pin<&mut ListExprElement>;
114
115 type StructExprField;
116 fn id(self: &StructExprField) -> i64;
117 fn set_id(self: Pin<&mut StructExprField>, id: i64);
118 fn name(self: &StructExprField) -> &CxxString;
119 fn set_name<'a>(self: Pin<&mut StructExprField>, name: string_view<'a>);
120 fn has_value(self: &StructExprField) -> bool;
121 fn value(self: &StructExprField) -> &Expr;
122 #[rust_name = "value_mut"]
123 fn mutable_value(self: Pin<&mut StructExprField>) -> Pin<&mut Expr>;
124 fn set_value(self: Pin<&mut StructExprField>, value: UniquePtr<Expr>);
125 fn optional(self: &StructExprField) -> bool;
126 fn set_optional(self: Pin<&mut StructExprField>, optional: bool);
127
128 type StructExpr;
129 fn name(self: &StructExpr) -> &CxxString;
130 fn set_name<'a>(self: Pin<&mut StructExpr>, name: string_view<'a>);
131 fn fields(self: &StructExpr) -> &CxxVector<StructExprField>;
132 #[rust_name = "fields_mut"]
133 fn mutable_fields(self: Pin<&mut StructExpr>) -> Pin<&mut CxxVector<StructExprField>>;
134 fn add_fields(self: Pin<&mut StructExpr>) -> Pin<&mut StructExprField>;
135
136 type MapExprEntry;
137 fn id(self: &MapExprEntry) -> i64;
138 fn set_id(self: Pin<&mut MapExprEntry>, id: i64);
139
140 fn has_key(self: &MapExprEntry) -> bool;
141 fn key(self: &MapExprEntry) -> &Expr;
142 #[rust_name = "key_mut"]
143 fn mutable_key(self: Pin<&mut MapExprEntry>) -> Pin<&mut Expr>;
144 fn set_key(self: Pin<&mut MapExprEntry>, key: UniquePtr<Expr>);
145
146 fn has_value(self: &MapExprEntry) -> bool;
147 fn value(self: &MapExprEntry) -> &Expr;
148 #[rust_name = "value_mut"]
149 fn mutable_value(self: Pin<&mut MapExprEntry>) -> Pin<&mut Expr>;
150 fn set_value(self: Pin<&mut MapExprEntry>, value: UniquePtr<Expr>);
151
152 fn optional(self: &MapExprEntry) -> bool;
153 fn set_optional(self: Pin<&mut MapExprEntry>, optional: bool);
154
155 type MapExpr;
156 fn entries(self: &MapExpr) -> &CxxVector<MapExprEntry>;
157 #[rust_name = "entries_mut"]
158 fn mutable_entries(self: Pin<&mut MapExpr>) -> Pin<&mut CxxVector<MapExprEntry>>;
159 fn add_entries(self: Pin<&mut MapExpr>) -> Pin<&mut MapExprEntry>;
160
161 type ComprehensionExpr;
162 fn iter_var(self: &ComprehensionExpr) -> &CxxString;
163 fn set_iter_var<'a>(self: Pin<&mut ComprehensionExpr>, iter_var: string_view<'a>);
164
165 fn iter_var2(self: &ComprehensionExpr) -> &CxxString;
166 fn set_iter_var2<'a>(self: Pin<&mut ComprehensionExpr>, iter_var2: string_view<'a>);
167
168 fn has_iter_range(self: &ComprehensionExpr) -> bool;
169 fn iter_range(self: &ComprehensionExpr) -> &Expr;
170 #[rust_name = "iter_range_mut"]
171 fn mutable_iter_range(self: Pin<&mut ComprehensionExpr>) -> Pin<&mut Expr>;
172 fn set_iter_range(self: Pin<&mut ComprehensionExpr>, iter_range: UniquePtr<Expr>);
173 fn release_iter_range(self: Pin<&mut ComprehensionExpr>) -> UniquePtr<Expr>;
174
175 fn accu_var(self: &ComprehensionExpr) -> &CxxString;
176 fn set_accu_var<'a>(self: Pin<&mut ComprehensionExpr>, accu_var: string_view<'a>);
177
178 fn has_accu_init(self: &ComprehensionExpr) -> bool;
179 fn accu_init(self: &ComprehensionExpr) -> &Expr;
180 #[rust_name = "accu_init_mut"]
181 fn mutable_accu_init(self: Pin<&mut ComprehensionExpr>) -> Pin<&mut Expr>;
182 fn set_accu_init(self: Pin<&mut ComprehensionExpr>, accu_init: UniquePtr<Expr>);
183 fn release_accu_init(self: Pin<&mut ComprehensionExpr>) -> UniquePtr<Expr>;
184
185 fn has_loop_condition(self: &ComprehensionExpr) -> bool;
186 fn loop_condition(self: &ComprehensionExpr) -> &Expr;
187 #[rust_name = "loop_condition_mut"]
188 fn mutable_loop_condition(self: Pin<&mut ComprehensionExpr>) -> Pin<&mut Expr>;
189 fn set_loop_condition(self: Pin<&mut ComprehensionExpr>, loop_condition: UniquePtr<Expr>);
190 fn release_loop_condition(self: Pin<&mut ComprehensionExpr>) -> UniquePtr<Expr>;
191
192 fn has_loop_step(self: &ComprehensionExpr) -> bool;
193 fn loop_step(self: &ComprehensionExpr) -> &Expr;
194 #[rust_name = "loop_step_mut"]
195 fn mutable_loop_step(self: Pin<&mut ComprehensionExpr>) -> Pin<&mut Expr>;
196 fn set_loop_step(self: Pin<&mut ComprehensionExpr>, loop_step: UniquePtr<Expr>);
197 fn release_loop_step(self: Pin<&mut ComprehensionExpr>) -> UniquePtr<Expr>;
198
199 fn has_result(self: &ComprehensionExpr) -> bool;
200 fn result(self: &ComprehensionExpr) -> &Expr;
201 #[rust_name = "result_mut"]
202 fn mutable_result(self: Pin<&mut ComprehensionExpr>) -> Pin<&mut Expr>;
203 fn set_result(self: Pin<&mut ComprehensionExpr>, result: UniquePtr<Expr>);
204 fn release_result(self: Pin<&mut ComprehensionExpr>) -> UniquePtr<Expr>;
205 }
206
207 #[namespace = "rust::cel_cxx"]
208 unsafe extern "C++" {
209 include!(<cel-cxx-ffi/include/expr.h>);
210
211 fn Expr_new() -> UniquePtr<Expr>;
213 fn Expr_set_const_expr(expr: Pin<&mut Expr>, constant: UniquePtr<Constant>);
214 fn Expr_set_ident_expr(expr: Pin<&mut Expr>, ident_expr: UniquePtr<IdentExpr>);
215 fn Expr_set_select_expr(expr: Pin<&mut Expr>, select_expr: UniquePtr<SelectExpr>);
216 fn Expr_set_call_expr(expr: Pin<&mut Expr>, call_expr: UniquePtr<CallExpr>);
217 fn Expr_set_list_expr(expr: Pin<&mut Expr>, list_expr: UniquePtr<ListExpr>);
218 fn Expr_set_struct_expr(expr: Pin<&mut Expr>, struct_expr: UniquePtr<StructExpr>);
219 fn Expr_set_map_expr(expr: Pin<&mut Expr>, map_expr: UniquePtr<MapExpr>);
220 fn Expr_set_comprehension_expr(expr: Pin<&mut Expr>, comprehension_expr: UniquePtr<ComprehensionExpr>);
221
222 fn Expr_size_of() -> usize;
223 fn Expr_push_unique(expr: Pin<&mut CxxVector<Expr>>, value: UniquePtr<Expr>);
224 fn Expr_pop_unique(expr: Pin<&mut CxxVector<Expr>>) -> UniquePtr<Expr>;
225
226 fn ListExprElement_new() -> UniquePtr<ListExprElement>;
227 fn ListExprElement_size_of() -> usize;
228 fn ListExprElement_push_unique(list_element: Pin<&mut CxxVector<ListExprElement>>, value: UniquePtr<ListExprElement>);
229 fn ListExprElement_pop_unique(list_element: Pin<&mut CxxVector<ListExprElement>>) -> UniquePtr<ListExprElement>;
230
231 fn StructExprField_new() -> UniquePtr<StructExprField>;
232 fn StructExprField_size_of() -> usize;
233 fn StructExprField_push_unique(struct_field: Pin<&mut CxxVector<StructExprField>>, value: UniquePtr<StructExprField>);
234 fn StructExprField_pop_unique(struct_field: Pin<&mut CxxVector<StructExprField>>) -> UniquePtr<StructExprField>;
235
236 fn MapExprEntry_new() -> UniquePtr<MapExprEntry>;
237 fn MapExprEntry_size_of() -> usize;
238 fn MapExprEntry_push_unique(map_entry: Pin<&mut CxxVector<MapExprEntry>>, value: UniquePtr<MapExprEntry>);
239 fn MapExprEntry_pop_unique(map_entry: Pin<&mut CxxVector<MapExprEntry>>) -> UniquePtr<MapExprEntry>;
240 }
241}
242
243#[repr(i32)]
245#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
246pub enum ExprKindCase {
247 Unspecified = 0,
248 Constant,
249 Ident,
250 Select,
251 Call,
252 List,
253 Struct,
254 Map,
255 Comprehension,
256}
257
258unsafe impl cxx::ExternType for ExprKindCase {
259 type Id = cxx::type_id!("cel::ExprKindCase");
260 type Kind = cxx::kind::Trivial;
261}
262
263impl ExprKindCase {
264 pub fn is_unspecified(&self) -> bool {
265 *self == ExprKindCase::Unspecified
266 }
267
268 pub fn is_constant(&self) -> bool {
269 *self == ExprKindCase::Constant
270 }
271
272 pub fn is_ident(&self) -> bool {
273 *self == ExprKindCase::Ident
274 }
275
276 pub fn is_select(&self) -> bool {
277 *self == ExprKindCase::Select
278 }
279
280 pub fn is_call(&self) -> bool {
281 *self == ExprKindCase::Call
282 }
283
284 pub fn is_list(&self) -> bool {
285 *self == ExprKindCase::List
286 }
287
288 pub fn is_struct(&self) -> bool {
289 *self == ExprKindCase::Struct
290 }
291
292 pub fn is_map(&self) -> bool {
293 *self == ExprKindCase::Map
294 }
295
296 pub fn is_comprehension(&self) -> bool {
297 *self == ExprKindCase::Comprehension
298 }
299}
300
301pub use ffi::Expr;
303unsafe impl Send for Expr {}
304unsafe impl Sync for Expr {}
305
306impl Expr {
307 pub fn new() -> cxx::UniquePtr<Self> {
308 ffi::Expr_new()
309 }
310
311 pub fn set_const_expr(self: Pin<&mut Self>, constant: cxx::UniquePtr<Constant>) {
312 ffi::Expr_set_const_expr(self, constant);
313 }
314
315 pub fn set_ident_expr(self: Pin<&mut Self>, ident_expr: cxx::UniquePtr<IdentExpr>) {
316 ffi::Expr_set_ident_expr(self, ident_expr);
317 }
318
319 pub fn set_select_expr(self: Pin<&mut Self>, select_expr: cxx::UniquePtr<SelectExpr>) {
320 ffi::Expr_set_select_expr(self, select_expr);
321 }
322
323 pub fn set_call_expr(self: Pin<&mut Self>, call_expr: cxx::UniquePtr<CallExpr>) {
324 ffi::Expr_set_call_expr(self, call_expr);
325 }
326
327 pub fn set_list_expr(self: Pin<&mut Self>, list_expr: cxx::UniquePtr<ListExpr>) {
328 ffi::Expr_set_list_expr(self, list_expr);
329 }
330
331 pub fn set_struct_expr(self: Pin<&mut Self>, struct_expr: cxx::UniquePtr<StructExpr>) {
332 ffi::Expr_set_struct_expr(self, struct_expr);
333 }
334
335 pub fn set_map_expr(self: Pin<&mut Self>, map_expr: cxx::UniquePtr<MapExpr>) {
336 ffi::Expr_set_map_expr(self, map_expr);
337 }
338
339 pub fn set_comprehension_expr(self: Pin<&mut Self>, comprehension_expr: cxx::UniquePtr<ComprehensionExpr>) {
340 ffi::Expr_set_comprehension_expr(self, comprehension_expr);
341 }
342}
343
344impl SpanElement for Expr {
345 type TypeId = cxx::type_id!("rust::cel_cxx::Span_Expr");
346}
347
348impl MutSpanElement for Expr {
349 type TypeId = cxx::type_id!("rust::cel_cxx::MutSpan_Expr");
350}
351
352impl crate::SizedExternType for Expr {
353 fn size_of() -> usize {
354 ffi::Expr_size_of()
355 }
356}
357
358unsafe impl crate::cxx::UniquePtrVectorElement for Expr {
359 fn push_unique(v: Pin<&mut cxx::CxxVector<Self>>, value: cxx::UniquePtr<Self>) {
360 ffi::Expr_push_unique(v, value);
361 }
362
363 fn pop_unique(v: Pin<&mut cxx::CxxVector<Self>>) -> cxx::UniquePtr<Self> {
364 ffi::Expr_pop_unique(v)
365 }
366}
367
368pub use ffi::UnspecifiedExpr;
370unsafe impl Send for UnspecifiedExpr {}
371unsafe impl Sync for UnspecifiedExpr {}
372
373pub use ffi::IdentExpr;
375unsafe impl Send for IdentExpr {}
376unsafe impl Sync for IdentExpr {}
377
378pub use ffi::SelectExpr;
380unsafe impl Send for SelectExpr {}
381unsafe impl Sync for SelectExpr {}
382
383pub use ffi::CallExpr;
385unsafe impl Send for CallExpr {}
386unsafe impl Sync for CallExpr {}
387
388pub use ffi::ListExpr;
390unsafe impl Send for ListExpr {}
391unsafe impl Sync for ListExpr {}
392
393pub use ffi::StructExpr;
395unsafe impl Send for StructExpr {}
396unsafe impl Sync for StructExpr {}
397
398pub use ffi::MapExpr;
400unsafe impl Send for MapExpr {}
401unsafe impl Sync for MapExpr {}
402
403pub use ffi::ComprehensionExpr;
405unsafe impl Send for ComprehensionExpr {}
406unsafe impl Sync for ComprehensionExpr {}
407
408pub use ffi::ListExprElement;
410unsafe impl Send for ListExprElement {}
411unsafe impl Sync for ListExprElement {}
412
413impl ListExprElement {
414 pub fn new() -> cxx::UniquePtr<Self> {
415 ffi::ListExprElement_new()
416 }
417}
418
419impl SpanElement for ListExprElement {
420 type TypeId = cxx::type_id!("rust::cel_cxx::Span_ListExprElement");
421}
422
423impl MutSpanElement for ListExprElement {
424 type TypeId = cxx::type_id!("rust::cel_cxx::MutSpan_ListExprElement");
425}
426
427impl crate::SizedExternType for ListExprElement {
428 fn size_of() -> usize {
429 ffi::ListExprElement_size_of()
430 }
431}
432
433unsafe impl crate::cxx::UniquePtrVectorElement for ListExprElement {
434 fn push_unique(v: Pin<&mut cxx::CxxVector<Self>>, value: cxx::UniquePtr<Self>) {
435 ffi::ListExprElement_push_unique(v, value);
436 }
437
438 fn pop_unique(v: Pin<&mut cxx::CxxVector<Self>>) -> cxx::UniquePtr<Self> {
439 ffi::ListExprElement_pop_unique(v)
440 }
441}
442
443pub use ffi::StructExprField;
445unsafe impl Send for StructExprField {}
446unsafe impl Sync for StructExprField {}
447
448impl StructExprField {
449 pub fn new() -> cxx::UniquePtr<Self> {
450 ffi::StructExprField_new()
451 }
452}
453
454impl SpanElement for StructExprField {
455 type TypeId = cxx::type_id!("rust::cel_cxx::Span_StructExprField");
456}
457impl MutSpanElement for StructExprField {
458 type TypeId = cxx::type_id!("rust::cel_cxx::MutSpan_StructExprField");
459}
460
461impl crate::SizedExternType for StructExprField {
462 fn size_of() -> usize {
463 ffi::StructExprField_size_of()
464 }
465}
466
467unsafe impl crate::cxx::UniquePtrVectorElement for StructExprField {
468 fn push_unique(v: Pin<&mut cxx::CxxVector<Self>>, value: cxx::UniquePtr<Self>) {
469 ffi::StructExprField_push_unique(v, value);
470 }
471
472 fn pop_unique(v: Pin<&mut cxx::CxxVector<Self>>) -> cxx::UniquePtr<Self> {
473 ffi::StructExprField_pop_unique(v)
474 }
475}
476
477pub use ffi::MapExprEntry;
479unsafe impl Send for MapExprEntry {}
480unsafe impl Sync for MapExprEntry {}
481
482impl MapExprEntry {
483 pub fn new() -> cxx::UniquePtr<Self> {
484 ffi::MapExprEntry_new()
485 }
486}
487
488impl SpanElement for MapExprEntry {
489 type TypeId = cxx::type_id!("rust::cel_cxx::Span_MapExprEntry");
490}
491
492impl MutSpanElement for MapExprEntry {
493 type TypeId = cxx::type_id!("rust::cel_cxx::MutSpan_MapExprEntry");
494}
495
496impl crate::SizedExternType for MapExprEntry {
497 fn size_of() -> usize {
498 ffi::MapExprEntry_size_of()
499 }
500}
501
502unsafe impl crate::cxx::UniquePtrVectorElement for MapExprEntry {
503 fn push_unique(v: Pin<&mut cxx::CxxVector<Self>>, value: cxx::UniquePtr<Self>) {
504 ffi::MapExprEntry_push_unique(v, value);
505 }
506
507 fn pop_unique(v: Pin<&mut cxx::CxxVector<Self>>) -> cxx::UniquePtr<Self> {
508 ffi::MapExprEntry_pop_unique(v)
509 }
510}