Skip to content

Commit

Permalink
Adds convert for u64
Browse files Browse the repository at this point in the history
  • Loading branch information
gupnik committed May 2, 2024
1 parent 6e7257c commit b07deeb
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions substrate/primitives/runtime/src/type_with_default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,21 +89,30 @@ impl<T, D: Get<T>> Default for TypeWithDefault<T, D> {
}
}

impl<T: From<u16>, D: Get<T>> From<u16> for TypeWithDefault<T, D> {
fn from(value: u16) -> Self {
Self::new(value.into())
}
}

impl<T: From<u32>, D: Get<T>> From<u32> for TypeWithDefault<T, D> {
fn from(value: u32) -> Self {
Self::new(value.into())
}
}
impl<T: From<u16>, D: Get<T>> From<u16> for TypeWithDefault<T, D> {
fn from(value: u16) -> Self {

impl<T: From<u64>, D: Get<T>> From<u64> for TypeWithDefault<T, D> {
fn from(value: u64) -> Self {
Self::new(value.into())
}
}

impl<T: CheckedNeg, D: Get<T>> CheckedNeg for TypeWithDefault<T, D> {
fn checked_neg(&self) -> Option<Self> {
self.0.checked_neg().map(Self::new)
}
}

impl<T: CheckedRem, D: Get<T>> CheckedRem for TypeWithDefault<T, D> {
fn checked_rem(&self, rhs: &Self) -> Option<Self> {
self.0.checked_rem(&rhs.0).map(Self::new)
Expand Down Expand Up @@ -206,13 +215,6 @@ impl<T: Display, D: Get<T>> Display for TypeWithDefault<T, D> {
}
}

impl<T: TryFrom<u64>, D: Get<T>> TryFrom<u64> for TypeWithDefault<T, D> {
type Error = <T as TryFrom<u64>>::Error;
fn try_from(n: u64) -> Result<TypeWithDefault<T, D>, Self::Error> {
T::try_from(n).map(Self::new)
}
}

impl<T: TryFrom<u128>, D: Get<T>> TryFrom<u128> for TypeWithDefault<T, D> {
type Error = <T as TryFrom<u128>>::Error;
fn try_from(n: u128) -> Result<TypeWithDefault<T, D>, Self::Error> {
Expand Down

0 comments on commit b07deeb

Please sign in to comment.