Skip to content

Commit

Permalink
Deprecate from_slice in favor of the new from_bytes fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Robbepop committed Oct 23, 2018
1 parent 5982371 commit ef4a8d8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -161,12 +161,28 @@ macro_rules! construct_hash {
}

/// Convert a slice of bytes of length `len()` to an instance of this type.
#[deprecated(
since = "0.3.0",
note = "unconventional API without proper bounds checking, use `from_bytes` instead"
)]
pub fn from_slice(src: &[u8]) -> Self {
let mut r = Self::zero();
r.clone_from_slice(src);
r
}

/// Create a new fixed-hash from the given slice `src`.
///
/// # Panics
///
/// If the length of `src` and the number of bytes in `Self` do not match.
pub fn from_bytes(src: &[u8]) -> Self {
assert_eq!(src.len(), $n_bytes);
let mut ret = Self::zero();
ret.assign_from_slice(src);
ret
}

/// Copy the data of this object into some mutable slice of length `len()`.
pub fn copy_to(&self, dest: &mut [u8]) {
let min = $crate::core::cmp::min($n_bytes, dest.len());
Expand Down

0 comments on commit ef4a8d8

Please sign in to comment.