diff options
Diffstat (limited to 'src/lib.rs')
| -rw-r--r-- | src/lib.rs | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -135,6 +135,7 @@ mod join; use arrayref::{array_mut_ref, array_ref}; use arrayvec::{ArrayString, ArrayVec}; +use core::array::TryFromSliceError; use core::cmp; use core::fmt; use platform::{Platform, MAX_SIMD_DEGREE, MAX_SIMD_DEGREE_OR_2}; @@ -239,7 +240,7 @@ impl Hash { /// Create a `Hash` from its raw bytes representation as a slice. /// /// Returns an error if the slice is not exactly 32 bytes long. - pub fn from_slice(bytes: &[u8]) -> Result<Self, core::array::TryFromSliceError> { + pub fn from_slice(bytes: &[u8]) -> Result<Self, TryFromSliceError> { Ok(Self::from_bytes(bytes.try_into()?)) } @@ -305,6 +306,14 @@ impl From<Hash> for [u8; OUT_LEN] { } } +impl TryFrom<&[u8]> for Hash { + type Error = TryFromSliceError; + + fn try_from(slice: &[u8]) -> Result<Self, Self::Error> { + Self::from_slice(slice) + } +} + impl core::str::FromStr for Hash { type Err = HexError; |
