| David Tolnay | 0beba91 | 2020-12-09 23:42:07 -0800 | [diff] [blame] | 1 | use crate::syntax::atom::Atom::{self, *}; |
| 2 | use crate::syntax::{derive, Trait, Type, Types}; |
| 3 | |
| 4 | impl<'a> Types<'a> { |
| 5 | pub 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(_) |
| David Tolnay | 215e77f | 2020-12-28 17:09:48 -0800 | [diff] [blame] | 29 | | Type::WeakPtr(_) |
| David Tolnay | 0beba91 | 2020-12-09 23:42:07 -0800 | [diff] [blame] | 30 | | Type::CxxVector(_) |
| 31 | | Type::Void(_) => false, |
| 32 | Type::Ref(_) | Type::Str(_) | Type::Fn(_) | Type::SliceRef(_) => true, |
| 33 | Type::Array(array) => self.is_guaranteed_pod(&array.inner), |
| 34 | } |
| 35 | } |
| 36 | } |