Skip to content

Commit

Permalink
Move AsRef impl block next to Index
Browse files Browse the repository at this point in the history
These two traits are related, in as much as they both give access to the
inner byte array. Put them next to each other to assist clarity.
  • Loading branch information
tcharding committed Nov 17, 2022
1 parent 4d42e8e commit 9850550
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
18 changes: 9 additions & 9 deletions secp256k1-sys/src/macros.rs
Expand Up @@ -45,15 +45,6 @@ macro_rules! impl_array_newtype {
}
}

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
}
}

// We cannot derive these traits because Rust 1.41.1 requires `std::array::LengthAtMost32`.

#[cfg(fuzzing)]
Expand Down Expand Up @@ -90,6 +81,15 @@ macro_rules! impl_array_newtype {
}
}

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<I> core::ops::Index<I> for $thing
where
[$ty]: core::ops::Index<I>,
Expand Down
18 changes: 9 additions & 9 deletions src/macros.rs
Expand Up @@ -18,15 +18,6 @@
macro_rules! impl_array_newtype {
($thing:ident, $ty:ty, $len:expr) => {

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
}
}

// We cannot derive these traits because Rust 1.41.1 requires `std::array::LengthAtMost32`.

impl PartialEq for $thing {
Expand Down Expand Up @@ -58,6 +49,15 @@ macro_rules! impl_array_newtype {
}
}

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<I> core::ops::Index<I> for $thing
where
[$ty]: core::ops::Index<I>,
Expand Down

0 comments on commit 9850550

Please sign in to comment.