aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 37c2c0b..355668f 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -236,6 +236,13 @@ impl Hash {
Self(bytes)
}
+ /// 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> {
+ Ok(Self::from_bytes(bytes.try_into()?))
+ }
+
/// Encode a `Hash` in lowercase hexadecimal.
///
/// The returned [`ArrayString`] is a fixed size and doesn't allocate memory