cel_cxx_ffi/common/
decl.rs1use crate::absl::{Duration, Status, Timestamp};
2use crate::common::{Type, Constant};
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 = super::Constant;
29 }
30
31 #[namespace = "rust::cel_cxx"]
32 unsafe extern "C++" {
33 include!(<cel-cxx-ffi/include/absl.h>);
34 include!(<cel-cxx-ffi/include/decl.h>);
35
36 fn VariableDecl_new<'a>(name: &str, ty: &Type<'a>) -> UniquePtr<VariableDecl<'a>>;
38 fn VariableDecl_new_constant<'a>(
39 name: &str,
40 value: &Constant,
41 ) -> UniquePtr<VariableDecl<'a>>;
42
43 fn FunctionDecl_new<'a>(name: &str) -> UniquePtr<FunctionDecl<'a>>;
45
46 fn OverloadDecl_new<'a>(
48 id: &str,
49 member: bool,
50 result: &Type<'a>,
51 args: &[Type<'a>],
52 ) -> UniquePtr<OverloadDecl<'a>>;
53 }
54}
55
56pub use ffi::VariableDecl;
57unsafe impl Send for VariableDecl<'_> {}
58unsafe impl Sync for VariableDecl<'_> {}
59
60impl<'a> VariableDecl<'a> {
61 pub fn new(name: &str, ty: &Type<'a>) -> cxx::UniquePtr<Self> {
62 ffi::VariableDecl_new(name, ty)
63 }
64
65 pub fn new_constant(name: &str, value: &Constant) -> cxx::UniquePtr<Self> {
66 ffi::VariableDecl_new_constant(name, value)
67 }
68}
69
70pub use ffi::FunctionDecl;
71unsafe impl Send for FunctionDecl<'_> {}
72unsafe impl Sync for FunctionDecl<'_> {}
73
74impl<'a> FunctionDecl<'a> {
75 pub fn new(name: &str) -> cxx::UniquePtr<Self> {
76 ffi::FunctionDecl_new(name)
77 }
78}
79
80pub use ffi::OverloadDecl;
81unsafe impl Send for OverloadDecl<'_> {}
82unsafe impl Sync for OverloadDecl<'_> {}
83
84impl<'a> OverloadDecl<'a> {
85 pub fn new(
86 id: &str,
87 member: bool,
88 result: &Type<'a>,
89 arguments: &[Type<'a>],
90 ) -> cxx::UniquePtr<Self> {
91 ffi::OverloadDecl_new(id, member, result, arguments)
92 }
93}