Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions glib-macros/src/boxed_derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result<TokenStream> {

#impl_from_value

unsafe impl #crate_ident::translate::TransparentPtrType for #name {}

impl #crate_ident::translate::GlibPtrDefault for #name {
type GlibType = *mut #name;
}
Expand Down
17 changes: 17 additions & 0 deletions glib-macros/tests/test.rs
Original file line number Diff line number Diff line change
@@ -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},
};
Expand Down Expand Up @@ -183,6 +184,22 @@ fn derive_boxed_nullable() {
assert_eq!(None, v.get::<Option<MyNullableBoxed>>().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")]
Expand Down