Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 2 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ proptest = { default-features = false, optional = true, features = ["std"], vers
rand = { default-features = false, optional = true, version = "0.8" }
rand-0_9 = { default-features = false, optional = true, package = "rand", version = "0.9" }
rust_decimal_macros = { path = "macros", default-features = false, optional = true, version = "1" }
rkyv = { default-features = false, features = ["size_32", "std"], optional = true, version = "0.7.42" }
rkyv = { default-features = false, features = ["pointer_width_32"], optional = true, version = "0.8.13" }
rocket = { default-features = false, optional = true, version = "0.5.0-rc.3" }
ryu = { default-features = false, optional = true, version = "1.0" }
serde = { default-features = false, optional = true, version = "1.0" }
Expand All @@ -47,7 +47,6 @@ diesel = { default-features = false, features = ["mysql", "postgres"], version =
futures = { default-features = false, version = "0.3" }
rand = { default-features = false, features = ["getrandom"], version = "0.8" }
rand-0_9 = { default-features = false, features = ["thread_rng"], package = "rand", version = "0.9" }
rkyv-0_8 = { version = "0.8", package = "rkyv" }
rust_decimal_macros = { path = "macros" }
serde = { default-features = false, features = ["derive"], version = "1.0" }
serde_json = "1.0"
Expand Down Expand Up @@ -76,7 +75,7 @@ ndarray = ["dep:ndarray"]
proptest = ["dep:proptest"]
rand = ["dep:rand"]
rkyv = ["dep:rkyv"]
rkyv-safe = ["rkyv/validation"]
rkyv-safe = ["rkyv/bytecheck"]
rocket-traits = ["dep:rocket", "std"]
rust-fuzz = ["dep:arbitrary"]
serde = ["dep:serde"]
Expand Down
2 changes: 0 additions & 2 deletions examples/rkyv-remote.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
extern crate rkyv_0_8 as rkyv;

use rkyv::{rancor::Error, Archive, Deserialize, Serialize};
use rust_decimal::prelude::{dec, Decimal};

Expand Down
5 changes: 2 additions & 3 deletions src/decimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,10 +109,9 @@ pub struct UnpackedDecimal {
#[cfg_attr(
feature = "rkyv",
derive(Archive, Deserialize, Serialize),
archive(compare(PartialEq)),
archive_attr(derive(Clone, Copy, Debug))
rkyv(compare(PartialEq), derive(Clone, Copy, Debug))
)]
#[cfg_attr(feature = "rkyv-safe", archive(check_bytes))]
#[cfg_attr(feature = "rkyv-safe", rkyv(bytecheck()))]
pub struct Decimal {
// Bits 0-15: unused
// Bits 16-23: Contains "e", a value between 0-28 that indicates the scale
Expand Down
10 changes: 5 additions & 5 deletions tests/decimal_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,31 +220,31 @@ mod ndarray_tests {

#[cfg(feature = "rkyv")]
mod rkyv_tests {
use rkyv::rancor::Error;
use rust_decimal::Decimal;
use std::str::FromStr;

#[test]
fn it_can_serialize_deserialize_rkyv() {
use rkyv::Deserialize;
let tests = [
"12.3456789",
"5233.9008808150288439427720175",
"-5233.9008808150288439427720175",
];
for test in &tests {
let a = Decimal::from_str(test).unwrap();
let bytes = rkyv::to_bytes::<_, 256>(&a).unwrap();
let bytes = rkyv::to_bytes::<Error>(&a).unwrap();

#[cfg(feature = "rkyv-safe")]
{
let archived = rkyv::check_archived_root::<Decimal>(&bytes[..]).unwrap();
let archived = rkyv::access::<<Decimal as rkyv::Archive>::Archived, Error>(&bytes[..]).unwrap();
assert_eq!(archived, &a);
}

let archived = unsafe { rkyv::archived_root::<Decimal>(&bytes[..]) };
let archived = unsafe { rkyv::access_unchecked::<<Decimal as rkyv::Archive>::Archived>(&bytes[..]) };
assert_eq!(archived, &a);

let deserialized: Decimal = archived.deserialize(&mut rkyv::Infallible).unwrap();
let deserialized: Decimal = rkyv::deserialize::<Decimal, Error>(archived).unwrap();
assert_eq!(deserialized, a);
}
}
Expand Down