Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add scalar division to per_things
  • Loading branch information
gavofyork committed Mar 12, 2021
commit 42a0be1ec3a78f2d0d1ff44b7e36c9f75134bf4c
9 changes: 8 additions & 1 deletion primitives/arithmetic/src/per_things.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
#[cfg(feature = "std")]
use serde::{Serialize, Deserialize};

use sp_std::{ops, fmt, prelude::*, convert::TryInto};
use sp_std::{ops, fmt, prelude::*, convert::{TryFrom, TryInto}};
use codec::{Encode, CompactAs};
use num_traits::Pow;
use crate::traits::{
Expand Down Expand Up @@ -660,6 +660,13 @@ macro_rules! implement_per_thing {
}
}

impl<N> ops::Div<N> for $name where $type: TryFrom<N> {
type Output = Self;
fn div(self, b: N) -> Self::Output {
<$type>::try_from(b).map_or(Self::zero(), |d| Self::from_parts(self.0 / d))
}
}

#[cfg(test)]
mod $test_mod {
use codec::{Encode, Decode};
Expand Down