Vendor dependencies

This commit is contained in:
2026-08-01 16:11:49 +03:00
parent 7f139a0241
commit 6b5e7f0f8b
29706 changed files with 9575646 additions and 0 deletions
+19
View File
@@ -0,0 +1,19 @@
# Examples
This contains some more advanced examples of using the rust decimal library of complex usage.
All examples are crate based to demonstrate feature configurations. Examples can be run by using:
```shell
cd examples/<example-name>
cargo run
```
## serde-json-scenarios
This example shows how to use the `serde` crate to serialize and deserialize the `Decimal` type using multiple different
serialization formats.
## rkyv-remote
This example shows shows how to use the `rkyv` crate's remote derive for the `Decimal` type.
@@ -0,0 +1,35 @@
extern crate rkyv_0_8 as rkyv;
use rkyv::{rancor::Error, Archive, Deserialize, Serialize};
use rust_decimal::prelude::{dec, Decimal};
/// 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);
}