Skip to content

[fixed-hash] Add deprecations in favor of the upcoming 0.3 major version #72

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 28, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fixed-hash/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "fixed-hash"
version = "0.2.4"
version = "0.2.5"
authors = ["Parity Technologies <[email protected]>"]
license = "MIT"
homepage = "https://github.com/paritytech/parity-common"
Expand Down
49 changes: 49 additions & 0 deletions fixed-hash/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
// except according to those terms.

/// Return `s` without the `0x` at the beginning of it, if any.
#[deprecated(
since = "0.2.5",
note = "out of scope for fixed-hash"
)]
pub fn clean_0x(s: &str) -> &str {
if s.starts_with("0x") {
&s[2..]
Expand Down Expand Up @@ -40,6 +44,10 @@ macro_rules! construct_hash {
}
}

#[deprecated(
since = "0.2.5",
note = "use `as_ref` instead"
)]
impl ::core::ops::Deref for $from {
type Target = [u8];

Expand Down Expand Up @@ -70,6 +78,10 @@ macro_rules! construct_hash {
}
}

#[deprecated(
since = "0.2.5",
note = "use `as_mut` instead"
)]
impl ::core::ops::DerefMut for $from {
#[inline]
fn deref_mut(&mut self) -> &mut [u8] {
Expand All @@ -79,6 +91,10 @@ macro_rules! construct_hash {

impl $from {
/// Create a new, zero-initialised, instance.
#[deprecated(
since = "0.2.5",
note = "use `fixed_hash`::zero constructor instead"
)]
pub fn new() -> $from {
$from([0; $size])
}
Expand All @@ -89,6 +105,10 @@ macro_rules! construct_hash {
}

/// Get the size of this object in bytes.
#[deprecated(
since = "0.2.5",
note = "will be renamed to `len_bytes` to avoid confusion"
)]
pub fn len() -> usize {
$size
}
Expand All @@ -104,26 +124,42 @@ macro_rules! construct_hash {

#[inline]
/// Assign self to be of the same value as a slice of bytes of length `len()`.
#[deprecated(
since = "0.2.5",
note = "unconventional API, replaced by `assign_from_slice` in version 0.3"
)]
pub fn clone_from_slice(&mut self, src: &[u8]) -> usize {
let min = ::core::cmp::min($size, src.len());
self.0[..min].copy_from_slice(&src[..min]);
min
}

/// Convert a slice of bytes of length `len()` to an instance of this type.
#[deprecated(
since = "0.2.5",
note = "unconventional API, replaced by `new_from_slice` in version 0.3"
)]
pub fn from_slice(src: &[u8]) -> Self {
let mut r = Self::new();
r.clone_from_slice(src);
r
}

/// Copy the data of this object into some mutable slice of length `len()`.
#[deprecated(
since = "0.2.5",
note = "use `std::slice` API instead"
)]
pub fn copy_to(&self, dest: &mut[u8]) {
let min = ::core::cmp::min($size, dest.len());
dest[..min].copy_from_slice(&self.0[..min]);
}

/// Returns `true` if all bits set in `b` are also set in `self`.
#[deprecated(
since = "0.2.5",
note = "will be renamed to `covers` in version 0.3"
)]
pub fn contains<'a>(&'a self, b: &'a Self) -> bool {
&(b & self) == b
}
Expand All @@ -134,6 +170,10 @@ macro_rules! construct_hash {
}

/// Returns the lowest 8 bytes interpreted as a BigEndian integer.
#[deprecated(
since = "0.2.5",
note = "will be renamed to `low_u64_be` in version 0.3"
)]
pub fn low_u64(&self) -> u64 {
let mut ret = 0u64;
for i in 0..::core::cmp::min($size, 8) {
Expand Down Expand Up @@ -178,6 +218,7 @@ macro_rules! construct_hash {
}

impl Copy for $from {}

#[cfg_attr(feature="dev", allow(expl_impl_clone_on_copy))]
impl Clone for $from {
fn clone(&self) -> $from {
Expand Down Expand Up @@ -309,6 +350,10 @@ macro_rules! construct_hash {
fn default() -> Self { $from::new() }
}

#[deprecated(
since = "0.2.5",
note = "will be removed because not big-/little-endian aware"
)]
impl From<u64> for $from {
fn from(mut value: u64) -> $from {
let mut ret = $from::new();
Expand All @@ -322,6 +367,10 @@ macro_rules! construct_hash {
}
}

#[deprecated(
since = "0.2.5",
note = "misses proper error handling; will be replaced by `new_from_slice` in version 0.3"
)]
impl<'a> From<&'a [u8]> for $from {
fn from(s: &'a [u8]) -> $from {
$from::from_slice(s)
Expand Down