cxxbridge_macro/syntax/
pod.rs

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