cel_cxx_ffi/common/
types.rs

1use crate::absl::{Span, SpanElement, StringView};
2use crate::common::TypeKind;
3use crate::protobuf::{Arena, DescriptorPool};
4use crate::Rep;
5
6#[cxx::bridge]
7mod ffi {
8    #[namespace = "google::protobuf"]
9    unsafe extern "C++" {
10        include!(<google/protobuf/arena.h>);
11        type Arena = super::Arena;
12
13        include!(<google/protobuf/descriptor.h>);
14        type DescriptorPool = super::DescriptorPool;
15    }
16
17    #[namespace = "absl"]
18    unsafe extern "C++" {
19        include!(<absl/strings/string_view.h>);
20        type string_view<'a> = super::StringView<'a>;
21    }
22
23    #[namespace = "cel"]
24    unsafe extern "C++" {
25        include!(<base/kind.h>);
26        type TypeKind = super::TypeKind;
27
28        include!(<common/type.h>);
29        type Type<'a> = super::Type<'a>;
30        fn name<'a>(self: &Type<'a>) -> string_view<'a>;
31        fn kind(self: &Type) -> TypeKind;
32
33        #[rust_name = "is_any"]
34        fn IsAny(self: &Type) -> bool;
35        #[rust_name = "is_bool"]
36        fn IsBool(self: &Type) -> bool;
37        #[rust_name = "is_bool_wrapper"]
38        fn IsBoolWrapper(self: &Type) -> bool;
39        #[rust_name = "is_bytes"]
40        fn IsBytes(self: &Type) -> bool;
41        #[rust_name = "is_bytes_wrapper"]
42        fn IsBytesWrapper(self: &Type) -> bool;
43        #[rust_name = "is_double"]
44        fn IsDouble(self: &Type) -> bool;
45        #[rust_name = "is_double_wrapper"]
46        fn IsDoubleWrapper(self: &Type) -> bool;
47        #[rust_name = "is_duration"]
48        fn IsDuration(self: &Type) -> bool;
49        #[rust_name = "is_dyn"]
50        fn IsDyn(self: &Type) -> bool;
51        #[rust_name = "is_enum"]
52        fn IsEnum(self: &Type) -> bool;
53        #[rust_name = "is_error"]
54        fn IsError(self: &Type) -> bool;
55        #[rust_name = "is_function"]
56        fn IsFunction(self: &Type) -> bool;
57        #[rust_name = "is_int"]
58        fn IsInt(self: &Type) -> bool;
59        #[rust_name = "is_int_wrapper"]
60        fn IsIntWrapper(self: &Type) -> bool;
61        #[rust_name = "is_list"]
62        fn IsList(self: &Type) -> bool;
63        #[rust_name = "is_map"]
64        fn IsMap(self: &Type) -> bool;
65        #[rust_name = "is_message"]
66        fn IsMessage(self: &Type) -> bool;
67        #[rust_name = "is_null"]
68        fn IsNull(self: &Type) -> bool;
69        #[rust_name = "is_opaque"]
70        fn IsOpaque(self: &Type) -> bool;
71        #[rust_name = "is_optional"]
72        fn IsOptional(self: &Type) -> bool;
73        #[rust_name = "is_string"]
74        fn IsString(self: &Type) -> bool;
75        #[rust_name = "is_string_wrapper"]
76        fn IsStringWrapper(self: &Type) -> bool;
77        #[rust_name = "is_struct"]
78        fn IsStruct(self: &Type) -> bool;
79        #[rust_name = "is_timestamp"]
80        fn IsTimestamp(self: &Type) -> bool;
81        #[rust_name = "is_type_param"]
82        fn IsTypeParam(self: &Type) -> bool;
83        #[rust_name = "is_type"]
84        fn IsType(self: &Type) -> bool;
85        #[rust_name = "is_uint"]
86        fn IsUint(self: &Type) -> bool;
87        #[rust_name = "is_uint_wrapper"]
88        fn IsUintWrapper(self: &Type) -> bool;
89        #[rust_name = "is_unknown"]
90        fn IsUnknown(self: &Type) -> bool;
91
92        #[rust_name = "get_enum"]
93        fn GetEnum<'a>(self: &Type<'a>) -> EnumType<'a>;
94        #[rust_name = "get_function"]
95        fn GetFunction<'a>(self: &Type<'a>) -> FunctionType<'a>;
96        #[rust_name = "get_list"]
97        fn GetList<'a>(self: &Type<'a>) -> ListType<'a>;
98        #[rust_name = "get_map"]
99        fn GetMap<'a>(self: &Type<'a>) -> MapType<'a>;
100        #[rust_name = "get_message"]
101        fn GetMessage<'a>(self: &Type<'a>) -> MessageType<'a>;
102        #[rust_name = "get_opaque"]
103        fn GetOpaque<'a>(self: &Type<'a>) -> OpaqueType<'a>;
104        #[rust_name = "get_optional"]
105        fn GetOptional<'a>(self: &Type<'a>) -> OptionalType<'a>;
106        #[rust_name = "get_struct"]
107        fn GetStruct<'a>(self: &Type<'a>) -> StructType<'a>;
108        #[rust_name = "get_type_param"]
109        fn GetTypeParam<'a>(self: &Type<'a>) -> TypeParamType<'a>;
110        #[rust_name = "get_type"]
111        fn GetType<'a>(self: &Type<'a>) -> TypeType<'a>;
112
113        type EnumType<'a> = super::EnumType<'a>;
114        fn name<'a>(self: &EnumType<'a>) -> string_view<'a>;
115
116        type FunctionType<'a> = super::FunctionType<'a>;
117        #[rust_name = "arguments"]
118        fn args<'a>(self: &FunctionType<'a>) -> Span_Type<'a, 'a>;
119        fn result<'a>(self: &FunctionType<'a>) -> &'a Type<'a>;
120
121        type ListType<'a> = super::ListType<'a>;
122        #[rust_name = "element"]
123        fn GetElement<'a>(self: &ListType<'a>) -> Type<'a>;
124        type MapType<'a> = super::MapType<'a>;
125        #[rust_name = "key"]
126        fn GetKey<'a>(self: &MapType<'a>) -> Type<'a>;
127        #[rust_name = "value"]
128        fn GetValue<'a>(self: &MapType<'a>) -> Type<'a>;
129
130        type MessageType<'a> = super::MessageType<'a>;
131        fn name<'a>(self: &MessageType<'a>) -> string_view<'a>;
132
133        type OpaqueType<'a> = super::OpaqueType<'a>;
134        fn name<'a>(self: &OpaqueType<'a>) -> string_view<'a>;
135        #[rust_name = "parameters"]
136        fn GetParameters<'a>(self: &OpaqueType<'a>) -> TypeParameters<'a>;
137        #[rust_name = "is_optional"]
138        fn IsOptional(self: &OpaqueType) -> bool;
139        #[rust_name = "as_optional"]
140        fn GetOptional<'a>(self: &OpaqueType<'a>) -> OptionalType<'a>;
141
142        type OptionalType<'a> = super::OptionalType<'a>;
143        #[rust_name = "parameter"]
144        fn GetParameter<'a>(self: &OptionalType<'a>) -> Type<'a>;
145
146        type StructType<'a> = super::StructType<'a>;
147        fn name<'a>(self: &StructType<'a>) -> string_view<'a>;
148        #[rust_name = "get_parameters"]
149        fn GetParameters<'a>(self: &StructType<'a>) -> TypeParameters<'a>;
150        #[rust_name = "is_message"]
151        fn IsMessage(self: &StructType) -> bool;
152        #[rust_name = "get_message"]
153        fn GetMessage<'a>(self: &StructType<'a>) -> MessageType<'a>;
154
155        type TypeParamType<'a> = super::TypeParamType<'a>;
156        fn name<'a>(self: &TypeParamType<'a>) -> string_view<'a>;
157
158        type TypeType<'a> = super::TypeType<'a>;
159        #[rust_name = "get_type"]
160        fn GetType<'a>(self: &TypeType<'a>) -> Type<'a>;
161
162        type TypeParameters<'a> = super::TypeParameters<'a>;
163        #[rust_name = "len"]
164        fn size(self: &TypeParameters) -> usize;
165        #[rust_name = "is_empty"]
166        fn empty(self: &TypeParameters) -> bool;
167
168        type StructTypeField<'a> = super::StructTypeField<'a>;
169        fn name<'a>(self: &StructTypeField<'a>) -> string_view<'a>;
170        fn number(self: &StructTypeField<'_>) -> i32;
171        #[rust_name = "get_type"]
172        fn GetType<'a>(self: &StructTypeField<'a>) -> Type<'a>;
173        #[rust_name = "is_message"]
174        fn IsMessage(self: &StructTypeField) -> bool;
175
176        type MessageTypeField<'a> = super::MessageTypeField<'a>;
177        fn name<'a>(self: &MessageTypeField<'a>) -> string_view<'a>;
178        fn number(self: &MessageTypeField<'_>) -> i32;
179        #[rust_name = "get_type"]
180        fn GetType<'a>(self: &MessageTypeField<'a>) -> Type<'a>;
181    }
182
183    #[namespace = "rust::cel_cxx"]
184    unsafe extern "C++" {
185        include!(<cel-cxx-ffi/include/types.h>);
186        type Span_Type<'s, 'a> = super::Span<'s, Type<'a>>;
187
188        fn Type_new_any() -> Type<'static>;
189        fn Type_new_bool() -> Type<'static>;
190        fn Type_new_bool_wrapper() -> Type<'static>;
191        fn Type_new_bytes() -> Type<'static>;
192        fn Type_new_bytes_wrapper() -> Type<'static>;
193        fn Type_new_double() -> Type<'static>;
194        fn Type_new_double_wrapper() -> Type<'static>;
195        fn Type_new_duration() -> Type<'static>;
196        fn Type_new_dyn() -> Type<'static>;
197        fn Type_new_enum<'a>(enum_type: &EnumType<'a>) -> Type<'a>;
198        fn Type_new_error() -> Type<'static>;
199        fn Type_new_function<'a>(function_type: &FunctionType<'a>) -> Type<'static>;
200        fn Type_new_int() -> Type<'static>;
201        fn Type_new_int_wrapper() -> Type<'static>;
202        fn Type_new_list<'a>(list_type: &ListType<'a>) -> Type<'a>;
203        fn Type_new_map<'a>(map_type: &MapType<'a>) -> Type<'a>;
204        fn Type_new_message<'a>(message_type: &MessageType<'a>) -> Type<'a>;
205        fn Type_new_null() -> Type<'static>;
206        fn Type_new_opaque<'a>(opaque_type: &OpaqueType<'a>) -> Type<'a>;
207        fn Type_new_optional<'a>(optional_type: &OptionalType<'a>) -> Type<'a>;
208        fn Type_new_string() -> Type<'static>;
209        fn Type_new_string_wrapper() -> Type<'static>;
210        fn Type_new_struct<'a>(struct_type: &StructType<'a>) -> Type<'a>;
211        fn Type_new_timestamp() -> Type<'static>;
212        fn Type_new_type_param<'a>(type_param_type: &TypeParamType<'a>) -> Type<'a>;
213        fn Type_new_type<'a>(type_type: &TypeType<'a>) -> Type<'a>;
214        fn Type_new_uint() -> Type<'static>;
215        fn Type_new_uint_wrapper() -> Type<'static>;
216        fn Type_new_unknown() -> Type<'static>;
217
218        // EnumType
219        fn EnumType_new<'a>(descriptor_pool: &'a DescriptorPool, name: &str) -> EnumType<'a>;
220
221        // FunctionType
222        fn FunctionType_new<'a>(
223            arena: &'a Arena,
224            result: &Type<'a>,
225            arguments: &[Type<'a>],
226        ) -> FunctionType<'a>;
227
228        // ListType
229        fn ListType_new<'a>(arena: &'a Arena, element: &Type<'a>) -> ListType<'a>;
230
231        // MapType
232        fn MapType_new<'a>(arena: &'a Arena, key: &Type<'a>, value: &Type<'a>) -> MapType<'a>;
233
234        // MessageType
235        fn MessageType_new<'a>(pool: &'a DescriptorPool, name: &str) -> MessageType<'a>;
236
237        // OpaqueType
238        fn OpaqueType_new<'a>(
239            arena: &'a Arena,
240            name: &str,
241            parameters: &[Type<'a>],
242        ) -> OpaqueType<'a>;
243
244        // OptionalType
245        fn OptionalType_default() -> OptionalType<'static>;
246        fn OptionalType_new<'a>(arena: &'a Arena, parameter: &Type<'a>) -> OptionalType<'a>;
247
248        // StructType
249        fn StructType_default() -> StructType<'static>;
250        fn StructType_new_message<'a>(message_type: &MessageType<'a>) -> StructType<'a>;
251        fn StructType_new_basic<'a>(name: &'a str) -> StructType<'a>;
252
253        // TypeParamType
254        fn TypeParamType_default() -> TypeParamType<'static>;
255        fn TypeParamType_new<'a>(name: &str, arena: &'a Arena) -> TypeParamType<'a>;
256
257        // TypeType
258        fn TypeType_default() -> TypeType<'static>;
259        fn TypeType_new<'a>(arena: &'a Arena, parameter: &Type<'a>) -> TypeType<'a>;
260        fn TypeType_has_type(type_type: &TypeType) -> bool;
261
262        // TypeParameters
263        unsafe fn TypeParameters_get_unchecked<'a>(
264            type_parameters: &TypeParameters<'a>,
265            index: usize,
266        ) -> &'a Type<'a>;
267
268        // StructTypeField
269        fn StructTypeField_new_basic<'a>(name: &'a str, number:i32, type_: &Type<'a>) -> StructTypeField<'a>;
270        fn StructTypeField_new_message<'a>(field: &MessageTypeField<'a>) -> StructTypeField<'a>;
271    }
272}
273
274// cel::Type is a variant of all subtypes.
275// The largest type is BasicStructType, TypeParamType which contains a
276// std::string_view.
277//
278// So we use 2 pointers size to store the type.
279#[repr(transparent)]
280#[derive(Copy, Clone)]
281pub struct Type<'a>(Rep<'a, usize, 3>);
282
283unsafe impl<'a> cxx::ExternType for Type<'a> {
284    type Id = cxx::type_id!("cel::Type");
285    type Kind = cxx::kind::Trivial;
286}
287
288impl<'a> crate::SizedExternType for Type<'a> {}
289
290impl<'a> SpanElement for Type<'a> {
291    type TypeId = cxx::type_id!("rust::cel_cxx::Span_Type");
292}
293
294impl<'a> Type<'a> {
295    pub fn new_any() -> Self {
296        ffi::Type_new_any()
297    }
298    pub fn new_bool() -> Self {
299        ffi::Type_new_bool()
300    }
301    pub fn new_bool_wrapper() -> Self {
302        ffi::Type_new_bool_wrapper()
303    }
304    pub fn new_bytes() -> Self {
305        ffi::Type_new_bytes()
306    }
307    pub fn new_bytes_wrapper() -> Self {
308        ffi::Type_new_bytes_wrapper()
309    }
310    pub fn new_double() -> Self {
311        ffi::Type_new_double()
312    }
313    pub fn new_double_wrapper() -> Self {
314        ffi::Type_new_double_wrapper()
315    }
316    pub fn new_duration() -> Self {
317        ffi::Type_new_duration()
318    }
319    pub fn new_dyn() -> Self {
320        ffi::Type_new_dyn()
321    }
322    pub fn new_enum(enum_type: &EnumType<'a>) -> Self {
323        ffi::Type_new_enum(enum_type)
324    }
325    pub fn new_error() -> Self {
326        ffi::Type_new_error()
327    }
328    pub fn new_function(function_type: &FunctionType<'a>) -> Self {
329        ffi::Type_new_function(function_type)
330    }
331    pub fn new_int() -> Self {
332        ffi::Type_new_int()
333    }
334    pub fn new_int_wrapper() -> Self {
335        ffi::Type_new_int_wrapper()
336    }
337    pub fn new_list(list_type: &ListType<'a>) -> Self {
338        ffi::Type_new_list(list_type)
339    }
340    pub fn new_map(map_type: &MapType<'a>) -> Self {
341        ffi::Type_new_map(map_type)
342    }
343    pub fn new_message(message_type: &MessageType<'a>) -> Self {
344        ffi::Type_new_message(message_type)
345    }
346    pub fn new_null() -> Self {
347        ffi::Type_new_null()
348    }
349    pub fn new_opaque(opaque_type: &OpaqueType<'a>) -> Self {
350        ffi::Type_new_opaque(opaque_type)
351    }
352    pub fn new_optional(optional_type: &OptionalType<'a>) -> Self {
353        ffi::Type_new_optional(optional_type)
354    }
355    pub fn new_string() -> Self {
356        ffi::Type_new_string()
357    }
358    pub fn new_string_wrapper() -> Self {
359        ffi::Type_new_string_wrapper()
360    }
361    pub fn new_struct(struct_type: &StructType<'a>) -> Self {
362        ffi::Type_new_struct(struct_type)
363    }
364    pub fn new_timestamp() -> Self {
365        ffi::Type_new_timestamp()
366    }
367    pub fn new_type_param(type_param_type: &TypeParamType<'a>) -> Self {
368        ffi::Type_new_type_param(type_param_type)
369    }
370    pub fn new_type(type_type: &TypeType<'a>) -> Self {
371        ffi::Type_new_type(type_type)
372    }
373    pub fn new_uint() -> Self {
374        ffi::Type_new_uint()
375    }
376    pub fn new_uint_wrapper() -> Self {
377        ffi::Type_new_uint_wrapper()
378    }
379    pub fn new_unknown() -> Self {
380        ffi::Type_new_unknown()
381    }
382}
383
384// EnumType stores a pointer to the descriptor.
385//
386// So we use 1 pointer size to store the type.
387#[repr(transparent)]
388#[derive(Copy, Clone)]
389pub struct EnumType<'a>(Rep<'a, usize, 1>);
390
391unsafe impl<'a> cxx::ExternType for EnumType<'a> {
392    type Id = cxx::type_id!("cel::EnumType");
393    type Kind = cxx::kind::Trivial;
394}
395
396impl<'a> EnumType<'a> {
397    pub fn new(descriptor_pool: &'a DescriptorPool, name: &str) -> Self {
398        ffi::EnumType_new(descriptor_pool, name)
399    }
400}
401
402// FunctionType stores a pointer.
403//
404// So we use 1 pointer size to store the type.
405#[repr(transparent)]
406#[derive(Copy, Clone)]
407pub struct FunctionType<'a>(Rep<'a, usize, 1>);
408
409unsafe impl<'a> cxx::ExternType for FunctionType<'a> {
410    type Id = cxx::type_id!("cel::FunctionType");
411    type Kind = cxx::kind::Trivial;
412}
413
414impl<'a> FunctionType<'a> {
415    pub fn new(arena: &'a Arena, result: &Type<'a>, arguments: &[Type<'a>]) -> Self {
416        ffi::FunctionType_new(arena, result, arguments)
417    }
418}
419
420// ListType stores a `uintptr_t`.
421//
422// So we use 1 pointer size to store the type.
423#[repr(transparent)]
424#[derive(Copy, Clone)]
425pub struct ListType<'a>(Rep<'a, usize, 1>);
426
427unsafe impl<'a> cxx::ExternType for ListType<'a> {
428    type Id = cxx::type_id!("cel::ListType");
429    type Kind = cxx::kind::Trivial;
430}
431
432impl<'a> ListType<'a> {
433    pub fn new(arena: &'a Arena, element: &Type<'a>) -> Self {
434        ffi::ListType_new(arena, element)
435    }
436}
437
438// MapType stores a `uintptr_t`.
439//
440// So we use 1 pointer size to store the type.
441#[repr(transparent)]
442#[derive(Copy, Clone)]
443pub struct MapType<'a>(Rep<'a, usize, 1>);
444
445unsafe impl<'a> cxx::ExternType for MapType<'a> {
446    type Id = cxx::type_id!("cel::MapType");
447    type Kind = cxx::kind::Trivial;
448}
449
450impl<'a> MapType<'a> {
451    pub fn new(arena: &'a Arena, key: &Type<'a>, value: &Type<'a>) -> Self {
452        ffi::MapType_new(arena, key, value)
453    }
454}
455
456// MessageType stores a pointer to the descriptor.
457//
458// So we use 1 pointer size to store the type.
459#[repr(transparent)]
460#[derive(Copy, Clone)]
461pub struct MessageType<'a>(Rep<'a, usize, 1>);
462
463unsafe impl<'a> cxx::ExternType for MessageType<'a> {
464    type Id = cxx::type_id!("cel::MessageType");
465    type Kind = cxx::kind::Trivial;
466}
467
468impl<'a> MessageType<'a> {
469    pub fn new(pool: &'a DescriptorPool, name: &str) -> Self {
470        ffi::MessageType_new(pool, name)
471    }
472}
473
474// OpaqueType stores a pointer to the data.
475//
476// So we use 1 pointer size to store the type.
477#[repr(transparent)]
478#[derive(Copy, Clone)]
479pub struct OpaqueType<'a>(Rep<'a, usize, 1>);
480
481unsafe impl<'a> cxx::ExternType for OpaqueType<'a> {
482    type Id = cxx::type_id!("cel::OpaqueType");
483    type Kind = cxx::kind::Trivial;
484}
485
486impl<'a> OpaqueType<'a> {
487    pub fn new(arena: &'a Arena, name: &str, parameters: &[Type<'a>]) -> Self {
488        ffi::OpaqueType_new(arena, name, parameters)
489    }
490}
491
492// OptionalType is a wrapper on OpaqueType.
493//
494// So we use 1 pointer size to store the type.
495#[repr(transparent)]
496#[derive(Copy, Clone)]
497pub struct OptionalType<'a>(Rep<'a, usize, 1>);
498
499unsafe impl<'a> cxx::ExternType for OptionalType<'a> {
500    type Id = cxx::type_id!("cel::OptionalType");
501    type Kind = cxx::kind::Trivial;
502}
503
504impl Default for OptionalType<'static> {
505    fn default() -> Self {
506        ffi::OptionalType_default()
507    }
508}
509
510impl<'a> OptionalType<'a> {
511    pub fn new(arena: &'a Arena, parameter: &Type<'a>) -> Self {
512        ffi::OptionalType_new(arena, parameter)
513    }
514}
515
516// StructType contains a StructTypeVariant, which largest member is
517// BasicStructType contains a std::string_view.
518//
519// So we use 2 pointers size to store the type.
520#[repr(transparent)]
521#[derive(Copy, Clone)]
522pub struct StructType<'a>(Rep<'a, usize, 2>);
523
524unsafe impl<'a> cxx::ExternType for StructType<'a> {
525    type Id = cxx::type_id!("cel::StructType");
526    type Kind = cxx::kind::Trivial;
527}
528
529impl Default for StructType<'static> {
530    fn default() -> Self {
531        ffi::StructType_default()
532    }
533}
534
535impl<'a> StructType<'a> {
536    pub fn new_message(message_type: &MessageType<'a>) -> Self {
537        ffi::StructType_new_message(message_type)
538    }
539    pub fn new_basic(name: &'a str) -> Self {
540        ffi::StructType_new_basic(name)
541    }
542}
543
544// TypeParamType stores a std::string_view.
545//
546// So we use 1 pointer size to store the type.
547#[repr(transparent)]
548#[derive(Copy, Clone)]
549pub struct TypeParamType<'a>(Rep<'a, usize, 1>);
550
551unsafe impl<'a> cxx::ExternType for TypeParamType<'a> {
552    type Id = cxx::type_id!("cel::TypeParamType");
553    type Kind = cxx::kind::Trivial;
554}
555
556impl Default for TypeParamType<'static> {
557    fn default() -> Self {
558        ffi::TypeParamType_default()
559    }
560}
561
562impl<'a> TypeParamType<'a> {
563    pub fn new(name: &str, arena: &'a Arena) -> Self {
564        ffi::TypeParamType_new(name, arena)
565    }
566}
567
568// TypeType stores a pointer to the data.
569//
570// So we use 1 pointer size to store the type.
571#[repr(transparent)]
572#[derive(Copy, Clone)]
573pub struct TypeType<'a>(Rep<'a, usize, 1>);
574
575unsafe impl<'a> cxx::ExternType for TypeType<'a> {
576    type Id = cxx::type_id!("cel::TypeType");
577    type Kind = cxx::kind::Trivial;
578}
579
580impl Default for TypeType<'static> {
581    fn default() -> Self {
582        ffi::TypeType_default()
583    }
584}
585
586impl<'a> TypeType<'a> {
587    pub fn new(arena: &'a Arena, parameter: &Type<'a>) -> Self {
588        ffi::TypeType_new(arena, parameter)
589    }
590    pub fn has_type(&self) -> bool {
591        ffi::TypeType_has_type(self)
592    }
593}
594
595// TypeParameters stores a size_t and a array of two `Type`s.
596//
597// So we use 5 pointers size to store the type.
598#[repr(transparent)]
599#[derive(Copy, Clone)]
600pub struct TypeParameters<'a>(Rep<'a, usize, 5>);
601
602unsafe impl<'a> cxx::ExternType for TypeParameters<'a> {
603    type Id = cxx::type_id!("cel::TypeParameters");
604    type Kind = cxx::kind::Trivial;
605}
606
607impl<'a> TypeParameters<'a> {
608    pub fn iter(&self) -> TypeParametersIter<'a> {
609        TypeParametersIter {
610            type_parameters: *self,
611            index: 0,
612        }
613    }
614
615    pub fn get(&self, index: usize) -> Option<&Type<'a>> {
616        if index < self.len() {
617            Some(unsafe { self.get_unchecked(index) })
618        } else {
619            None
620        }
621    }
622
623    /// Get a type parameter at the specified index without bounds checking.
624    ///
625    /// # Safety
626    ///
627    /// The caller must ensure that `index` is less than `self.len()`.
628    /// Calling this method with an out-of-bounds index is undefined behavior.
629    pub unsafe fn get_unchecked(&self, index: usize) -> &Type<'a> {
630        unsafe { ffi::TypeParameters_get_unchecked(self, index) }
631    }
632}
633
634impl<'a> std::iter::IntoIterator for TypeParameters<'a> {
635    type Item = Type<'a>;
636    type IntoIter = TypeParametersIter<'a>;
637
638    fn into_iter(self) -> Self::IntoIter {
639        self.iter()
640    }
641}
642
643impl<'a> std::ops::Index<usize> for TypeParameters<'a> {
644    type Output = Type<'a>;
645
646    fn index(&self, index: usize) -> &Self::Output {
647        unsafe { self.get_unchecked(index) }
648    }
649}
650
651pub struct TypeParametersIter<'a> {
652    type_parameters: TypeParameters<'a>,
653    index: usize,
654}
655
656impl<'a> std::iter::Iterator for TypeParametersIter<'a> {
657    type Item = Type<'a>;
658
659    fn next(&mut self) -> Option<Self::Item> {
660        if self.index < self.type_parameters.len() {
661            let item = self.type_parameters[self.index];
662            self.index += 1;
663            Some(item)
664        } else {
665            None
666        }
667    }
668
669    fn size_hint(&self) -> (usize, Option<usize>) {
670        (
671            self.type_parameters.len() - self.index,
672            Some(self.type_parameters.len() - self.index),
673        )
674    }
675}
676
677impl<'a> std::iter::ExactSizeIterator for TypeParametersIter<'a> {
678    fn len(&self) -> usize {
679        self.type_parameters.len() - self.index
680    }
681}
682
683impl<'a> std::iter::FusedIterator for TypeParametersIter<'a> {}
684
685// StructTypeField
686#[repr(transparent)]
687#[derive(Copy, Clone)]
688pub struct StructTypeField<'a>(Rep<'a, usize, 7>);
689
690unsafe impl<'a> cxx::ExternType for StructTypeField<'a> {
691    type Id = cxx::type_id!("cel::StructTypeField");
692    type Kind = cxx::kind::Trivial;
693}
694
695impl<'a> StructTypeField<'a> {
696    pub fn new_basic(name: &'a str, number:i32, type_: &Type<'a>) -> Self {
697        ffi::StructTypeField_new_basic(name, number, type_)
698    }
699
700    pub fn new_message(field: &MessageTypeField<'a>) -> Self {
701        ffi::StructTypeField_new_message(field)
702    }
703}
704
705// MessageTypeField
706#[repr(transparent)]
707#[derive(Copy, Clone)]
708pub struct MessageTypeField<'a>(Rep<'a, usize, 1>);
709
710unsafe impl<'a> cxx::ExternType for MessageTypeField<'a> {
711    type Id = cxx::type_id!("cel::MessageTypeField");
712    type Kind = cxx::kind::Trivial;
713}
714
715impl<'a> MessageTypeField<'a> {
716}