-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
52 additions
and
6 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
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,36 @@ | ||
extern crate rkyv_0_8 as rkyv; | ||
|
||
use rkyv::{rancor::Error, Archive, Deserialize, Serialize}; | ||
use rust_decimal::Decimal; | ||
use rust_decimal_macros::dec; | ||
|
||
/// The type containing a [`Decimal`] that will be de/serialized. | ||
#[derive(Archive, Serialize, Deserialize, Debug, PartialEq, Eq)] | ||
struct Root { | ||
#[rkyv(with = RkyvDecimal)] | ||
decimal: Decimal, | ||
} | ||
|
||
/// Archived layout of [`Decimal`] | ||
#[derive(Archive, Serialize, Deserialize)] | ||
#[rkyv(remote = Decimal)] | ||
struct RkyvDecimal { | ||
#[rkyv(getter = Decimal::serialize)] | ||
bytes: [u8; 16], | ||
} | ||
|
||
impl From<RkyvDecimal> for Decimal { | ||
fn from(RkyvDecimal { bytes }: RkyvDecimal) -> Self { | ||
Self::deserialize(bytes) | ||
} | ||
} | ||
|
||
fn main() { | ||
let test_value = Root { decimal: dec!(123.456) }; | ||
|
||
let bytes = rkyv::to_bytes::<Error>(&test_value).expect("Failed to serialize"); | ||
|
||
let roundtrip_value = rkyv::from_bytes::<Root, Error>(&bytes).expect("Failed to deserialize"); | ||
|
||
assert_eq!(test_value, roundtrip_value); | ||
} |
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