-
Notifications
You must be signed in to change notification settings - Fork 218
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
fixed-hash: remove rustc-hex
feature
#873
Conversation
1c300b1
to
0b6e1e5
Compare
2f08a2d
to
8892ac3
Compare
@ordian Is there anyone else who can review this PR? |
quickcheck = { version = "1", optional = true } | ||
rand = { version = "0.8.0", optional = true, default-features = false } | ||
rustc-hex = { version = "2.0.1", optional = true, default-features = false } | ||
const-hex = { version = "1.13", default-features = false } |
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.
why is const-hex
not an optional dependency because rustc-hex
was that before?
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.
rustc-hex
is only used for std::str::FromStr
impl, IMO, I don't think the feature is necessary.
if rustc-hex
has a trait, like rustc_hex::Trait
, and we need to impl rustc_hex::Trait for H256
, then I agree that we should add rustc-hex
as an optional feature.
another question: why is hex
not an optional dependency of uint
? 😕
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'm more concerned with a larger dependency tree for users that can't opt-out from it rather than a small impl inside this crate itself...
Lots of crates in this repo are very old and I don't think had a policy when to make it optional or not. Probably that's why we haven't been consistent
Anyway, I prefer to make const-hex
an optional dependency such that users can opt-out from it but included in the default features.
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 the most users don't learn anything from the name of the const-hex
feature, because it is only used in the implementation of std::str::FromStr
/core::str::FromStr
.
so why we add an optional feature for a core/std trait impl? unless the impl has multiple implementations based on different features.
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 care more about ease of use and consistency
- ease of use: why I need use an optional
const-hex
feature when I want to usecore::str::FromStr
trait ofH256
- consistency: why other crates, like
uint
, not usinghex
as an optional dependency
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.
To be honest, this kind of feature declaration is not a good way.
If a type (likeH256
) has many core/std
trait implementations that depend on other crates, do we need to add many features for each crate? obviously, this is not a good idea.
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.
To rephrase what I mean if the feature is not part of the core functionality of the crate/type then it should be an optional feature IMO (especially if it needs extra dependencies)
I don't follow why you mean with H256 because it's re-exported from several crates such as fixed_hash, primitive_types and ethereum_types
For instance for ethereum-types it makes sense to have rustc-hex
as hard dependency because it's required to be able to parse hex strings in the ethereum-world IIRC but it's not necessarily case for fixed-hash because it's depends how it used but in most use-cases it's probably useful to have.
So, if you can motivate why it's essential From::hex_str
for these types then I'm fine to have it has hard dependency but we shouldn't use different libraries in uint
and fixed_hash
for those. If const_hex
is the way to go we should use it in uint
as well i.e, not both use hex and const_hex
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 don't follow why you mean with H256 because it's re-exported from several crates such as fixed_hash, primitive_types and ethereum_types
H256
is just a type as example.
If const_hex is the way to go we should use it in uint as well i.e, not both use hex and const_hex
see description:
BTW, I'm considering replacing both hex and rustc-hex in dependency tree with const-hex.
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.
OK, let me summarize:
-
Is
core::str::FromStr
one of the core functions offixed-hash
?
IMO, it is, so I will choose hex as its str parsing format (it will rely on a hex parsing library, whether it isconst-hex
/hex
/rustc-hex
, I chooseconst-hex
), of course, if it's other str format, we can consider using feature to distinguish them, but there is no such requirement now. -
Why do I say that the existing feature declaration (like
rustc-hex
feature) is not a good idea?I think features should only be used for:
- different implementations of the same function
- optional function
- support third-party libraries
From the existing design of fixed-hash
, core::str::FromStr
is its core function, and I think it should't support third-party libraries through features (keep fixed-hash
pure and avoid the restrictions of the orphan rule?), so there are specific types declared in primitive-types
and ethereum-types
and a series of impls
crates.
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.
Okey, thanks for the explanation.
It's not necessarily requires to have a FromStr
implementation to support parsing hex strings for fixed-hash but
as you say it's quite annoying to have a feature-flag for it and makes it harder for everyone.
So, I'm onboard to make this hex feature
required for the hash types but in the future if you want change stuff it's a much better way to open an issue to explain why something is bad and why you want to change it.
It's a more likely that we reject PRs that make breaking changes.
I don't want to submit PRs to a repo that doesn't give me timely feedback, so close it |
merge #872 firstrustc-hex
feature (rustc-hex
is only used forstd::str::FromStr
impl, so I don't think the feature is necessary)const-hex
instead ofrustc-hex
dependency (rustc-hex
is no longer maintained, andconst-hex
has better performance)BTW, I'm considering replacing both
hex
andrustc-hex
in dependency tree withconst-hex
.