Skip to content

Commit

Permalink
Implement AsRef instead of custom method
Browse files Browse the repository at this point in the history
Clippy emits a warning since we define a method that has the same name
as a standard trait. Implement the trait `AsRef` instead of using a
custom method.
  • Loading branch information
tcharding committed Dec 22, 2020
1 parent 3afc172 commit 02dec3e
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions secp256k1-sys/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ macro_rules! impl_array_newtype {
dat.as_mut_ptr()
}

#[inline]
/// Gets a reference to the underlying array
pub fn as_ref(&self) -> &[$ty; $len] {
let &$thing(ref dat) = self;
dat
}

#[inline]
/// Returns the length of the object as an array
pub fn len(&self) -> usize { $len }
Expand All @@ -50,6 +43,15 @@ macro_rules! impl_array_newtype {
pub fn is_empty(&self) -> bool { false }
}

impl AsRef<[$ty; $len]> for $thing {
#[inline]
/// Gets a reference to the underlying array
fn as_ref(&self) -> &[$ty; $len] {
let &$thing(ref dat) = self;
dat
}
}

impl PartialEq for $thing {
#[inline]
fn eq(&self, other: &$thing) -> bool {
Expand Down

0 comments on commit 02dec3e

Please sign in to comment.