Skip to content

Commit 9fdf2f6

Browse files
author
Hero Bird
authored
Merge pull request #72 from paritytech/pre-0.3-deprecations
[fixed-hash] Add deprecations in favor of the upcoming 0.3 major version
2 parents e16441a + 6f445ec commit 9fdf2f6

File tree

2 files changed

+50
-1
lines changed

2 files changed

+50
-1
lines changed

fixed-hash/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "fixed-hash"
3-
version = "0.2.4"
3+
version = "0.2.5"
44
authors = ["Parity Technologies <[email protected]>"]
55
license = "MIT"
66
homepage = "https://github.com/paritytech/parity-common"

fixed-hash/src/hash.rs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
// except according to those terms.
88

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

47+
#[deprecated(
48+
since = "0.2.5",
49+
note = "use `as_ref` instead"
50+
)]
4351
impl ::core::ops::Deref for $from {
4452
type Target = [u8];
4553

@@ -70,6 +78,10 @@ macro_rules! construct_hash {
7078
}
7179
}
7280

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

8092
impl $from {
8193
/// Create a new, zero-initialised, instance.
94+
#[deprecated(
95+
since = "0.2.5",
96+
note = "use `fixed_hash`::zero constructor instead"
97+
)]
8298
pub fn new() -> $from {
8399
$from([0; $size])
84100
}
@@ -89,6 +105,10 @@ macro_rules! construct_hash {
89105
}
90106

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

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

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

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

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

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

180220
impl Copy for $from {}
221+
181222
#[cfg_attr(feature="dev", allow(expl_impl_clone_on_copy))]
182223
impl Clone for $from {
183224
fn clone(&self) -> $from {
@@ -309,6 +350,10 @@ macro_rules! construct_hash {
309350
fn default() -> Self { $from::new() }
310351
}
311352

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

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

0 commit comments

Comments
 (0)