-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add BorshSerialize & BorshDeserialize behind feature flag
- Loading branch information
1 parent
6e3d361
commit 87dbf77
Showing
8 changed files
with
154 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Changelog | ||
|
||
All notable changes to `const-decimal`. | ||
|
||
## Unreleased | ||
|
||
- Added `BorshSerialize` and `BorshDeserialize` behind `borsh` feature flag. | ||
- Added `AddAssign`, `SubAssign`, `MulAssign`, and `DivAssign`. | ||
|
||
## 0.1.0 | ||
|
||
- Initialize release. |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use borsh::{BorshDeserialize, BorshSerialize}; | ||
use proptest::prelude::*; | ||
|
||
use crate::macros::generate_tests_for_common_variants; | ||
use crate::{Decimal, Integer}; | ||
|
||
generate_tests_for_common_variants!(round_trip_borsh); | ||
|
||
fn round_trip_borsh<I, const D: u8>() | ||
where | ||
I: Integer<D> + Arbitrary + BorshSerialize + BorshDeserialize, | ||
{ | ||
proptest!(|(input: Decimal<I, D>)| { | ||
let serialized = borsh::to_vec(&input).unwrap(); | ||
let recovered = borsh::from_slice(&serialized).unwrap(); | ||
|
||
prop_assert_eq!(input, recovered); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#[cfg(feature = "borsh")] | ||
mod borsh; | ||
#[cfg(test)] | ||
mod malachite; | ||
#[cfg(test)] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
macro_rules! apply_to_common_variants { | ||
($macro:ident) => { | ||
$macro!(u8, 1); | ||
$macro!(i8, 1); | ||
$macro!(u16, 2); | ||
$macro!(i16, 2); | ||
$macro!(u32, 5); | ||
$macro!(i32, 5); | ||
$macro!(u64, 9); | ||
$macro!(i64, 9); | ||
$macro!(u128, 18); | ||
$macro!(i128, 18); | ||
}; | ||
} | ||
|
||
macro_rules! generate_tests_for_common_variants { | ||
($f:ident) => { | ||
crate::macros::generate_test!($f, u8, 1); | ||
crate::macros::generate_test!($f, i8, 1); | ||
crate::macros::generate_test!($f, u16, 2); | ||
crate::macros::generate_test!($f, i16, 2); | ||
crate::macros::generate_test!($f, u32, 5); | ||
crate::macros::generate_test!($f, i32, 5); | ||
crate::macros::generate_test!($f, u64, 9); | ||
crate::macros::generate_test!($f, i64, 9); | ||
crate::macros::generate_test!($f, u128, 18); | ||
crate::macros::generate_test!($f, i128, 18); | ||
}; | ||
} | ||
|
||
macro_rules! generate_test { | ||
($f:ident, $underlying:ty, $decimals:literal) => { | ||
::paste::paste! { | ||
#[test] | ||
fn [<$f _ $underlying _ $decimals >]() { | ||
$f::<$underlying, $decimals>(); | ||
} | ||
} | ||
}; | ||
} | ||
|
||
pub(crate) use {apply_to_common_variants, generate_test, generate_tests_for_common_variants}; |