cxx_gen/syntax/pod.rs
1use crate::syntax::atom::Atom::{self, *};
2use crate::syntax::query::TypeQuery;
3use crate::syntax::{primitive, Types};
4
5impl<'a> Types<'a> {
6 pub(crate) fn is_guaranteed_pod(&self, ty: impl Into<TypeQuery<'a>>) -> bool {
7 match ty.into() {
8 TypeQuery::Ident(ident) => {
9 let ident = &ident.rust;
10 if let Some(atom) = Atom::from(ident) {
11 match atom {
12 Bool | Char | U8 | U16 | U32 | U64 | Usize | I8 | I16 | I32 | I64
13 | Isize | F32 | F64 => true,
14 CxxString | RustString => false,
15 }
16 } else if let Some(strct) = self.structs.get(ident) {
17 strct.fields.iter().all(|field| {
18 primitive::kind(&field.ty).is_none() && self.is_guaranteed_pod(&field.ty)
19 })
20 } else {
21 self.enums.contains_key(ident)
22 }
23 }
24 TypeQuery::RustBox
25 | TypeQuery::RustVec
26 | TypeQuery::UniquePtr
27 | TypeQuery::SharedPtr
28 | TypeQuery::WeakPtr
29 | TypeQuery::CxxVector
30 | TypeQuery::Void => false,
31 TypeQuery::Ref(_)
32 | TypeQuery::Str
33 | TypeQuery::Fn
34 | TypeQuery::SliceRef
35 | TypeQuery::Ptr(_) => true,
36 TypeQuery::Array(array) => self.is_guaranteed_pod(&array.inner),
37 }
38 }
39}