-
Notifications
You must be signed in to change notification settings - Fork 233
[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
Conversation
It looks like @Robbepop signed our Contributor License Agreement. 👍 Many thanks, Parity Technologies CLA Bot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good stuff, exactly what I was hoping for. Have some change suggestions for wording and a question.
fixed-hash/src/hash.rs
Outdated
@@ -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 = "implement this 3-liner yourself instead" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
:)
…but let's be Enterprise Ready® and say "out of scope of fixed-hash".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😅
fixed-hash/src/hash.rs
Outdated
@@ -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, will have a replacement in version 0.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we state what the replacement is? So: unconventional API, replaced by … … in 0.3
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep, would be better!
fixed-hash/src/hash.rs
Outdated
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, will have a replacement in version 0.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same.
fixed-hash/src/hash.rs
Outdated
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 = "simply use std slice API instead" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Drop the "simply": use the std::slice API instead
.
fixed-hash/src/hash.rs
Outdated
@@ -309,6 +350,10 @@ macro_rules! construct_hash { | |||
fn default() -> Self { $from::new() } | |||
} | |||
|
|||
#[deprecated( | |||
since = "0.2.5", | |||
note = "big-endian and little-endian confusion" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe will be removed because not big-/little-endian aware
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sounds better, thanks!
fixed-hash/src/hash.rs
Outdated
@@ -322,6 +367,10 @@ macro_rules! construct_hash { | |||
} | |||
} | |||
|
|||
#[deprecated( | |||
since = "0.2.5", | |||
note = "no proper error handling possible with out-of-bounds inputs" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remind me, what is the replacement for this in 0.3
? I could be wrong but I think this one is fairly often used.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had no concrete replacement API in mind for this but I would be O.K. with replacing this by a function:
fn from_slice(slice: &[u8]) -> $from {
assert_eq!(
$from::len_bytes(), slice.len(),
"[fixed-hash] error: cannot create a fixed-hash from a byte slice with different length"
);
$from::from(std::mem::transmute::<&[u8], &[u8; $n_bytes]>(slice))
}
Of course I really hope for not having to use mem::transmute
.
@dvdplm What has to be done in order to merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm!
NOTE
Description
Pre
0.3
deprecations forfixed-hash
crate as suggested by @dvdplm .Note that deprecation of trait implementations do not work in general for Rust.
Note sure how to handle those, especially for the
Deref
andDerefMut
trait implementations.Also note that there will be some more trait implementation deprecations coming with the future
0.3
release. Especially for the conversions that have no error handling so far.