diff --git a/glib-macros/src/boxed_derive.rs b/glib-macros/src/boxed_derive.rs index 8abd4fd08f0b..f70a89ac1bea 100644 --- a/glib-macros/src/boxed_derive.rs +++ b/glib-macros/src/boxed_derive.rs @@ -184,6 +184,8 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result { #impl_from_value + unsafe impl #crate_ident::translate::TransparentPtrType for #name {} + impl #crate_ident::translate::GlibPtrDefault for #name { type GlibType = *mut #name; } diff --git a/glib-macros/tests/test.rs b/glib-macros/tests/test.rs index c33487af5921..21fb1512bee8 100644 --- a/glib-macros/tests/test.rs +++ b/glib-macros/tests/test.rs @@ -1,6 +1,7 @@ // Take a look at the license at the top of the repository in the LICENSE file. use glib::{ + collections::PtrSlice, prelude::*, translate::{FromGlib, IntoGlib}, }; @@ -183,6 +184,22 @@ fn derive_boxed_nullable() { assert_eq!(None, v.get::>().unwrap()); } +#[test] +fn boxed_transparent_ptr() { + #[derive(Clone, Debug, PartialEq, Eq, glib::Boxed)] + #[boxed_type(name = "MyBoxed")] + struct MyBoxed(String); + + let vec = vec![MyBoxed(String::from("abc")), MyBoxed(String::from("dfg"))]; + + // PtrSlice requires TransparentPtrType trait + let ptr_slice = PtrSlice::from(vec); + assert_eq!( + ptr_slice.last(), + Some(MyBoxed(String::from("dfg"))).as_ref() + ); +} + #[test] fn attr_flags() { #[glib::flags(name = "MyFlags")]