Skip to content

Commit d68decf

Browse files
committed
list: mark as transparent and impl TransparentPtr
List and SList are wrappers around C pointers
1 parent 22a91c1 commit d68decf

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

glib/src/collections/list.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ use crate::translate::*;
88
/// A list of items of type `T`.
99
///
1010
/// Behaves like an `Iterator<Item = T>` but allows modifications.
11+
#[repr(transparent)]
1112
pub struct List<T: TransparentPtrType> {
1213
ptr: Option<ptr::NonNull<ffi::GList>>,
1314
phantom: PhantomData<T>,
1415
}
1516

17+
#[doc(hidden)]
18+
unsafe impl<T: TransparentPtrType> TransparentPtrType for List<T> {}
19+
20+
#[doc(hidden)]
21+
impl<T: TransparentPtrType> GlibPtrDefault for List<T> {
22+
type GlibType = *mut ffi::GList;
23+
}
24+
1625
unsafe impl<T: Send + TransparentPtrType> Send for List<T> {}
1726

1827
unsafe impl<T: Sync + TransparentPtrType> Sync for List<T> {}

glib/src/collections/slist.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,20 @@ use crate::translate::*;
88
/// A list of items of type `T`.
99
///
1010
/// Behaves like an `Iterator<Item = T>` but allows modifications.
11+
#[repr(transparent)]
1112
pub struct SList<T: TransparentPtrType> {
1213
ptr: Option<ptr::NonNull<ffi::GSList>>,
1314
phantom: PhantomData<T>,
1415
}
1516

17+
#[doc(hidden)]
18+
unsafe impl<T: TransparentPtrType> TransparentPtrType for SList<T> {}
19+
20+
#[doc(hidden)]
21+
impl<T: TransparentPtrType> GlibPtrDefault for SList<T> {
22+
type GlibType = *mut ffi::GSList;
23+
}
24+
1625
unsafe impl<T: Send + TransparentPtrType> Send for SList<T> {}
1726

1827
unsafe impl<T: Sync + TransparentPtrType> Sync for SList<T> {}

0 commit comments

Comments
 (0)