cel_cxx_ffi/common/
decl.rs1use crate::absl::{Duration, Status, Timestamp};
2use crate::common::Type;
3
4#[cxx::bridge]
5mod ffi {
6 #[namespace = "absl"]
7 unsafe extern "C++" {
8 include!(<absl/status/status.h>);
9 include!(<absl/time/time.h>);
10 type Status = super::Status;
11 type Time = super::Timestamp;
12 type Duration = super::Duration;
13 }
14
15 #[namespace = "cel"]
16 unsafe extern "C++" {
17 include!(<common/type.h>);
18 type Type<'a> = super::Type<'a>;
19
20 include!(<common/decl.h>);
21 type VariableDecl<'a>;
22 type OverloadDecl<'a>;
23 type FunctionDecl<'a>;
24 #[rust_name = "add_overload"]
25 fn AddOverload<'a>(self: Pin<&mut FunctionDecl<'a>>, overload: &OverloadDecl<'a>)
26 -> Status;
27
28 type Constant;
29 fn has_value(self: &Constant) -> bool;
30 fn has_null_value(self: &Constant) -> bool;
31 fn has_bool_value(self: &Constant) -> bool;
32 fn has_int_value(self: &Constant) -> bool;
33 fn has_uint_value(self: &Constant) -> bool;
34 fn has_double_value(self: &Constant) -> bool;
35 fn has_bytes_value(self: &Constant) -> bool;
36 fn has_string_value(self: &Constant) -> bool;
37 fn has_duration_value(self: &Constant) -> bool;
38 fn has_timestamp_value(self: &Constant) -> bool;
39 fn bool_value(self: &Constant) -> bool;
40 fn int_value(self: &Constant) -> i64;
41 fn uint_value(self: &Constant) -> u64;
42 fn double_value(self: &Constant) -> f64;
43 fn bytes_value(self: &Constant) -> &CxxString;
44 fn string_value(self: &Constant) -> &CxxString;
45 fn duration_value(self: &Constant) -> Duration;
46 fn timestamp_value(self: &Constant) -> Time;
47 }
48
49 #[namespace = "rust::cel_cxx"]
50 unsafe extern "C++" {
51 include!(<cel-cxx-ffi/include/absl.h>);
52 include!(<cel-cxx-ffi/include/decl.h>);
53
54 fn VariableDecl_new<'a>(name: &str, ty: &Type<'a>) -> UniquePtr<VariableDecl<'a>>;
56 fn VariableDecl_new_constant<'a>(
57 name: &str,
58 value: &Constant,
59 ) -> UniquePtr<VariableDecl<'a>>;
60
61 fn FunctionDecl_new<'a>(name: &str) -> UniquePtr<FunctionDecl<'a>>;
63
64 fn OverloadDecl_new<'a>(
66 id: &str,
67 member: bool,
68 result: &Type<'a>,
69 args: &[Type<'a>],
70 ) -> UniquePtr<OverloadDecl<'a>>;
71
72 fn Constant_new_null() -> UniquePtr<Constant>;
74 fn Constant_new_bool(value: bool) -> UniquePtr<Constant>;
75 fn Constant_new_int(value: i64) -> UniquePtr<Constant>;
76 fn Constant_new_uint(value: u64) -> UniquePtr<Constant>;
77 fn Constant_new_double(value: f64) -> UniquePtr<Constant>;
78 fn Constant_new_bytes(value: &[u8]) -> UniquePtr<Constant>;
79 fn Constant_new_string(value: &str) -> UniquePtr<Constant>;
80 fn Constant_new_duration(value: Duration) -> UniquePtr<Constant>;
81 fn Constant_new_timestamp(value: Time) -> UniquePtr<Constant>;
82 }
83}
84
85pub use ffi::VariableDecl;
86unsafe impl Send for VariableDecl<'_> {}
87unsafe impl Sync for VariableDecl<'_> {}
88
89impl<'a> VariableDecl<'a> {
90 pub fn new(name: &str, ty: &Type<'a>) -> cxx::UniquePtr<Self> {
91 ffi::VariableDecl_new(name, ty)
92 }
93
94 pub fn new_constant(name: &str, value: &Constant) -> cxx::UniquePtr<Self> {
95 ffi::VariableDecl_new_constant(name, value)
96 }
97}
98
99pub use ffi::Constant;
100unsafe impl Send for Constant {}
101unsafe impl Sync for Constant {}
102
103impl Constant {
104 pub fn new_null() -> cxx::UniquePtr<Self> {
105 ffi::Constant_new_null()
106 }
107
108 pub fn new_bool(value: bool) -> cxx::UniquePtr<Self> {
109 ffi::Constant_new_bool(value)
110 }
111
112 pub fn new_int(value: i64) -> cxx::UniquePtr<Self> {
113 ffi::Constant_new_int(value)
114 }
115
116 pub fn new_uint(value: u64) -> cxx::UniquePtr<Self> {
117 ffi::Constant_new_uint(value)
118 }
119
120 pub fn new_double(value: f64) -> cxx::UniquePtr<Self> {
121 ffi::Constant_new_double(value)
122 }
123
124 pub fn new_bytes(value: &[u8]) -> cxx::UniquePtr<Self> {
125 ffi::Constant_new_bytes(value)
126 }
127
128 pub fn new_string(value: &str) -> cxx::UniquePtr<Self> {
129 ffi::Constant_new_string(value)
130 }
131
132 pub fn new_duration(value: Duration) -> cxx::UniquePtr<Self> {
133 ffi::Constant_new_duration(value)
134 }
135
136 pub fn new_timestamp(value: Timestamp) -> cxx::UniquePtr<Self> {
137 ffi::Constant_new_timestamp(value)
138 }
139}
140
141pub use ffi::FunctionDecl;
142unsafe impl Send for FunctionDecl<'_> {}
143unsafe impl Sync for FunctionDecl<'_> {}
144
145impl<'a> FunctionDecl<'a> {
146 pub fn new(name: &str) -> cxx::UniquePtr<Self> {
147 ffi::FunctionDecl_new(name)
148 }
149}
150
151pub use ffi::OverloadDecl;
152unsafe impl Send for OverloadDecl<'_> {}
153unsafe impl Sync for OverloadDecl<'_> {}
154
155impl<'a> OverloadDecl<'a> {
156 pub fn new(
157 id: &str,
158 member: bool,
159 result: &Type<'a>,
160 arguments: &[Type<'a>],
161 ) -> cxx::UniquePtr<Self> {
162 ffi::OverloadDecl_new(id, member, result, arguments)
163 }
164}