Skip to content

Commit

Permalink
impl AsRef<Self> for primitives
Browse files Browse the repository at this point in the history
  • Loading branch information
debris committed Feb 21, 2018
1 parent 7450113 commit f539c7c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ macro_rules! construct_hash {
}
}

impl AsRef<$from> for $from {
#[inline]
fn as_ref(&self) -> &$from {
&self
}
}

impl ::core::ops::DerefMut for $from {
#[inline]
fn deref_mut(&mut self) -> &mut [u8] {
Expand Down
6 changes: 6 additions & 0 deletions uint/src/uint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,12 @@ macro_rules! construct_uint {
#[derive(Copy, Clone, Eq, PartialEq, Hash)]
pub struct $name(pub [u64; $n_words]);

impl AsRef<$name> for $name {
fn as_ref(&self) -> &$name {
&self
}
}

impl $name {
/// Convert from a decimal string.
pub fn from_dec_str(value: &str) -> Result<Self, $crate::FromDecStrErr> {
Expand Down

0 comments on commit f539c7c

Please sign in to comment.