Skip to content

Commit 6d9a350

Browse files
committed
glib-macros: Derived boxed types are not TransparentPtrType but TransparentType
I.e. they're equal to their FFI representation, not equal to a pointer of their FFI representation. Fixes #1554
1 parent 8c8b9b1 commit 6d9a350

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

glib-macros/src/boxed_derive.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,9 @@ pub fn impl_boxed(input: &syn::DeriveInput) -> syn::Result<TokenStream> {
192192

193193
#impl_from_value
194194

195-
unsafe impl #crate_ident::translate::TransparentPtrType for #name {}
195+
unsafe impl #crate_ident::translate::TransparentType for #name {
196+
type GlibType = #name;
197+
}
196198

197199
impl #crate_ident::translate::GlibPtrDefault for #name {
198200
type GlibType = *mut #name;

glib-macros/tests/test.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Take a look at the license at the top of the repository in the LICENSE file.
22

33
use glib::{
4-
collections::PtrSlice,
4+
collections::Slice,
55
prelude::*,
66
translate::{FromGlib, IntoGlib},
77
};
@@ -185,19 +185,16 @@ fn derive_boxed_nullable() {
185185
}
186186

187187
#[test]
188-
fn boxed_transparent_ptr() {
188+
fn boxed_transparent() {
189189
#[derive(Clone, Debug, PartialEq, Eq, glib::Boxed)]
190190
#[boxed_type(name = "MyBoxed")]
191191
struct MyBoxed(String);
192192

193193
let vec = vec![MyBoxed(String::from("abc")), MyBoxed(String::from("dfg"))];
194194

195-
// PtrSlice requires TransparentPtrType trait
196-
let ptr_slice = PtrSlice::from(vec);
197-
assert_eq!(
198-
ptr_slice.last(),
199-
Some(MyBoxed(String::from("dfg"))).as_ref()
200-
);
195+
// Slice requires TransparentType trait
196+
let slice = Slice::from(vec);
197+
assert_eq!(slice.last(), Some(MyBoxed(String::from("dfg"))).as_ref());
201198
}
202199

203200
#[test]

0 commit comments

Comments
 (0)