-
Notifications
You must be signed in to change notification settings - Fork 690
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
Support more types in TypeWithDefault #6411
base: master
Are you sure you want to change the base?
Conversation
Review required! Latest push from author must always be reviewed |
@NingLin-P there are still build issues. Could you please fix them? |
Signed-off-by: linning <linningde25@gmail.com>
5268cd8
to
1339613
Compare
Sorry about the force push noise! the previous solution does not work because |
Description
When using
TypeWithDefault<u32, ..>
as the default nonce provider to overcome the replay attack issue, it fails to compile due toTypeWithDefault<u32, ..>: TryFrom<u64>
is not satisfied (which is required by traitBaseArithmetic
).This is because the blanket implementation
TryFrom<U> for T where U: Into<T>
only implTryFrom<u16>
andTryFrom<u8>
foru32
sinceu32
only implInto
foru16
andu8
but notu64
.This PR fixes the issue by adding
TryFrom<u16/u32/u64/u128>
andFrom<u8/u16/u32/u64/u128>
impl (using macro) forTypeWithDefault<u8/u16/u32/u64/u128, ..>
and removing the blanket impl (otherwise the compiler will complain about conflicting impl), such thatTypeWithDefault<u8/u16/u32/u64/u128, ..>: AtLeast8/16/32Bit
is satisfied.Integration
This PR adds support to more types to be used with
TypeWithDefault
, existing code that usedu64
withTypeWithDefault
should not be affected, an unit test is added to ensure that.Review Notes
This PR simply makes
TypeWithDefault<u8/u16/u32/u64/u128, ..>: AtLeast8/16/32Bit
satisfied