Factor out helper for identifying maybe trivial types
diff --git a/gen/src/write.rs b/gen/src/write.rs
index 645b988..7285a64 100644
--- a/gen/src/write.rs
+++ b/gen/src/write.rs
@@ -1592,11 +1592,7 @@
// know at code generation time, so we generate both C++ and Rust side
// bindings for a "new" method anyway. But the Rust code can't be called
// for Opaque types because the 'new' method is not implemented.
- UniquePtr::Ident(ident) => {
- out.types.structs.contains_key(ident)
- || out.types.enums.contains_key(ident)
- || out.types.aliases.contains_key(ident)
- }
+ UniquePtr::Ident(ident) => out.types.is_maybe_trivial(ident),
UniquePtr::CxxVector(_) => false,
};
@@ -1704,9 +1700,7 @@
// know at code generation time, so we generate both C++ and Rust side
// bindings for a "new" method anyway. But the Rust code can't be called for
// Opaque types because the 'new' method is not implemented.
- let can_construct_from_value = out.types.structs.contains_key(ident)
- || out.types.enums.contains_key(ident)
- || out.types.aliases.contains_key(ident);
+ let can_construct_from_value = out.types.is_maybe_trivial(ident);
writeln!(
out,
diff --git a/macro/src/expand.rs b/macro/src/expand.rs
index b6815e2..ee82e26 100644
--- a/macro/src/expand.rs
+++ b/macro/src/expand.rs
@@ -1302,9 +1302,7 @@
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
- let can_construct_from_value = types.structs.contains_key(ident)
- || types.enums.contains_key(ident)
- || types.aliases.contains_key(ident);
+ let can_construct_from_value = types.is_maybe_trivial(ident);
let new_method = if can_construct_from_value {
Some(quote! {
#[doc(hidden)]
@@ -1398,9 +1396,7 @@
let (impl_generics, ty_generics) = generics::split_for_impl(key, explicit_impl, resolve);
- let can_construct_from_value = types.structs.contains_key(ident)
- || types.enums.contains_key(ident)
- || types.aliases.contains_key(ident);
+ let can_construct_from_value = types.is_maybe_trivial(ident);
let new_method = if can_construct_from_value {
Some(quote! {
#[doc(hidden)]
diff --git a/syntax/types.rs b/syntax/types.rs
index af7916d..5a9bca4 100644
--- a/syntax/types.rs
+++ b/syntax/types.rs
@@ -250,6 +250,14 @@
ImproperCtype::Depends(ident) => self.struct_improper_ctypes.contains(ident),
}
}
+
+ // Types which we need to assume could possibly exist by value on the Rust
+ // side.
+ pub fn is_maybe_trivial(&self, ty: &Ident) -> bool {
+ self.structs.contains_key(ty)
+ || self.enums.contains_key(ty)
+ || self.aliases.contains_key(ty)
+ }
}
impl<'t, 'a> IntoIterator for &'t Types<'a> {