Remove as_[mut_]ptr from impl_array_newtype macros

For interfacing with the FFI layer we implement `ffi::CPtr`, there is
not need to provide methods `as_ptr` and `as_mut_ptr` as well.
This commit is contained in:
Tobin C. Harding 2022-11-17 10:52:36 +11:00
parent 3e28070187
commit 2bb08c21e5
3 changed files with 12 additions and 50 deletions

View File

@ -20,20 +20,6 @@ macro_rules! impl_array_newtype {
impl Copy for $thing {}
impl $thing {
/// Converts the object to a raw pointer for FFI interfacing.
#[inline]
pub fn as_ptr(&self) -> *const $ty {
let &$thing(ref dat) = self;
dat.as_ptr()
}
/// Converts the object to a mutable raw pointer for FFI interfacing.
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut $ty {
let &mut $thing(ref mut dat) = self;
dat.as_mut_ptr()
}
/// Returns the length of the object as an array.
#[inline]
pub fn len(&self) -> usize { $len }
@ -101,20 +87,15 @@ macro_rules! impl_array_newtype {
impl $crate::CPtr for $thing {
type Target = $ty;
fn as_c_ptr(&self) -> *const Self::Target {
if self.is_empty() {
core::ptr::null()
} else {
self.as_ptr()
}
let &$thing(ref dat) = self;
dat.as_ptr()
}
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
if self.is_empty() {
core::ptr::null::<Self::Target>() as *mut _
} else {
self.as_mut_ptr()
}
let &mut $thing(ref mut dat) = self;
dat.as_mut_ptr()
}
}
}

View File

@ -146,7 +146,7 @@ pub fn shared_secret_point(point: &PublicKey, scalar: &SecretKey) -> [u8; 64] {
ffi::secp256k1_context_no_precomp,
xy.as_mut_ptr(),
point.as_c_ptr(),
scalar.as_ptr(),
scalar.as_c_ptr(),
Some(c_callback),
ptr::null_mut(),
)

View File

@ -20,20 +20,6 @@ macro_rules! impl_array_newtype {
impl Copy for $thing {}
impl $thing {
/// Converts the object to a raw pointer for FFI interfacing.
#[inline]
pub fn as_ptr(&self) -> *const $ty {
let &$thing(ref dat) = self;
dat.as_ptr()
}
/// Converts the object to a mutable raw pointer for FFI interfacing.
#[inline]
pub fn as_mut_ptr(&mut self) -> *mut $ty {
let &mut $thing(ref mut dat) = self;
dat.as_mut_ptr()
}
/// Returns the length of the object as an array.
#[inline]
pub fn len(&self) -> usize { $len }
@ -99,22 +85,17 @@ macro_rules! impl_array_newtype {
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
}
impl $crate::CPtr for $thing {
impl $crate::ffi::CPtr for $thing {
type Target = $ty;
fn as_c_ptr(&self) -> *const Self::Target {
if self.is_empty() {
core::ptr::null()
} else {
self.as_ptr()
}
let &$thing(ref dat) = self;
dat.as_ptr()
}
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
if self.is_empty() {
core::ptr::null::<Self::Target>() as *mut _
} else {
self.as_mut_ptr()
}
let &mut $thing(ref mut dat) = self;
dat.as_mut_ptr()
}
}
}