cel_cxx_ffi/common/
ast.rs

1use crate::common::Type;
2use crate::protobuf::{Arena, DescriptorPool};
3
4#[cxx::bridge]
5mod ffi {
6    #[namespace = "google::protobuf"]
7    unsafe extern "C++" {
8        include!(<google/protobuf/descriptor.h>);
9
10        type Arena = super::Arena;
11        type DescriptorPool = super::DescriptorPool;
12    }
13
14    #[namespace = "cel"]
15    unsafe extern "C++" {
16        include!(<common/type.h>);
17        type Type<'a> = super::Type<'a>;
18
19        include!(<common/ast.h>);
20        type TypeSpec;
21
22        type Ast;
23        #[rust_name = "is_checked"]
24        fn IsChecked(self: &Ast) -> bool;
25
26        #[rust_name = "return_type_spec"]
27        fn GetReturnType(self: &Ast) -> &TypeSpec;
28    }
29
30    #[namespace = "rust::cel_cxx"]
31    unsafe extern "C++" {
32        include!(<cel-cxx-ffi/include/ast.h>);
33
34        fn TypeSpec_to_type<'a>(
35            ast_type: &TypeSpec,
36            descriptor_pool: &DescriptorPool,
37            arena: &'a Arena,
38        ) -> Type<'a>;
39    }
40
41    impl UniquePtr<Ast> {}
42}
43
44pub use ffi::Ast;
45unsafe impl Send for Ast {}
46unsafe impl Sync for Ast {}
47
48impl Ast {
49    pub fn return_type<'a>(&self, descriptor_pool: &DescriptorPool, arena: &'a Arena) -> Type<'a> {
50        let type_spec = self.return_type_spec();
51        ffi::TypeSpec_to_type(type_spec, descriptor_pool, arena)
52    }
53}