Skip to content
This repository has been archived by the owner on Jun 8, 2021. It is now read-only.

Commit

Permalink
generate from_glib_borrow implementation for const pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
GuillaumeGomez committed Jan 21, 2019
1 parent 96493f1 commit 6e46421
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/boxed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,14 @@ macro_rules! glib_boxed_wrapper {
}
}

#[doc(hidden)]
impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
#[inline]
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
$crate::translate::from_glib_borrow(ptr as *mut $ffi_name)
}
}

#[doc(hidden)]
impl $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name {
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
Expand Down
11 changes: 10 additions & 1 deletion src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,11 +526,20 @@ macro_rules! glib_object_wrapper {
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe fn from_glib_borrow(ptr: *mut $ffi_name) -> Self {
debug_assert!($crate::types::instance_of::<Self>(ptr as *const _));
$name($crate::translate::from_glib_borrow(ptr as *mut _),
$name($crate::translate::from_glib_borrow(ptr as *mut $ffi_name),
::std::marker::PhantomData)
}
}

#[doc(hidden)]
impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
#[inline]
#[cfg_attr(feature = "cargo-clippy", allow(cast_ptr_alignment))]
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
$crate::translate::from_glib_borrow(ptr as *mut _)
}
}

#[doc(hidden)]
impl $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name {
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
Expand Down
8 changes: 8 additions & 0 deletions src/shared.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,14 @@ macro_rules! glib_shared_wrapper {
}
}

#[doc(hidden)]
impl $crate::translate::FromGlibPtrBorrow<*const $ffi_name> for $name {
#[inline]
unsafe fn from_glib_borrow(ptr: *const $ffi_name) -> Self {
$crate::translate::from_glib_borrow(ptr as *mut $ffi_name)
}
}

#[doc(hidden)]
impl $crate::translate::FromGlibContainerAsVec<*mut $ffi_name, *mut *mut $ffi_name> for $name {
unsafe fn from_glib_none_num_as_vec(ptr: *mut *mut $ffi_name, num: usize) -> Vec<Self> {
Expand Down

0 comments on commit 6e46421

Please sign in to comment.