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:
parent
3e28070187
commit
2bb08c21e5
|
@ -20,20 +20,6 @@ macro_rules! impl_array_newtype {
|
||||||
impl Copy for $thing {}
|
impl Copy for $thing {}
|
||||||
|
|
||||||
impl $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.
|
/// Returns the length of the object as an array.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn len(&self) -> usize { $len }
|
pub fn len(&self) -> usize { $len }
|
||||||
|
@ -101,20 +87,15 @@ macro_rules! impl_array_newtype {
|
||||||
|
|
||||||
impl $crate::CPtr for $thing {
|
impl $crate::CPtr for $thing {
|
||||||
type Target = $ty;
|
type Target = $ty;
|
||||||
|
|
||||||
fn as_c_ptr(&self) -> *const Self::Target {
|
fn as_c_ptr(&self) -> *const Self::Target {
|
||||||
if self.is_empty() {
|
let &$thing(ref dat) = self;
|
||||||
core::ptr::null()
|
dat.as_ptr()
|
||||||
} else {
|
|
||||||
self.as_ptr()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
|
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
|
||||||
if self.is_empty() {
|
let &mut $thing(ref mut dat) = self;
|
||||||
core::ptr::null::<Self::Target>() as *mut _
|
dat.as_mut_ptr()
|
||||||
} else {
|
|
||||||
self.as_mut_ptr()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,7 +146,7 @@ pub fn shared_secret_point(point: &PublicKey, scalar: &SecretKey) -> [u8; 64] {
|
||||||
ffi::secp256k1_context_no_precomp,
|
ffi::secp256k1_context_no_precomp,
|
||||||
xy.as_mut_ptr(),
|
xy.as_mut_ptr(),
|
||||||
point.as_c_ptr(),
|
point.as_c_ptr(),
|
||||||
scalar.as_ptr(),
|
scalar.as_c_ptr(),
|
||||||
Some(c_callback),
|
Some(c_callback),
|
||||||
ptr::null_mut(),
|
ptr::null_mut(),
|
||||||
)
|
)
|
||||||
|
|
|
@ -20,20 +20,6 @@ macro_rules! impl_array_newtype {
|
||||||
impl Copy for $thing {}
|
impl Copy for $thing {}
|
||||||
|
|
||||||
impl $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.
|
/// Returns the length of the object as an array.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn len(&self) -> usize { $len }
|
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] }
|
fn index(&self, index: I) -> &Self::Output { &self.0[index] }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl $crate::CPtr for $thing {
|
impl $crate::ffi::CPtr for $thing {
|
||||||
type Target = $ty;
|
type Target = $ty;
|
||||||
|
|
||||||
fn as_c_ptr(&self) -> *const Self::Target {
|
fn as_c_ptr(&self) -> *const Self::Target {
|
||||||
if self.is_empty() {
|
let &$thing(ref dat) = self;
|
||||||
core::ptr::null()
|
dat.as_ptr()
|
||||||
} else {
|
|
||||||
self.as_ptr()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
|
fn as_mut_c_ptr(&mut self) -> *mut Self::Target {
|
||||||
if self.is_empty() {
|
let &mut $thing(ref mut dat) = self;
|
||||||
core::ptr::null::<Self::Target>() as *mut _
|
dat.as_mut_ptr()
|
||||||
} else {
|
|
||||||
self.as_mut_ptr()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue