From 5700cb0b9f5388f6fb98f0c374186966bfdcf609 Mon Sep 17 00:00:00 2001 From: Corvin Paul Date: Sat, 7 Sep 2024 15:08:29 +0100 Subject: [PATCH] support for rust_decimal::Decimal rename rustdecimal_impl and smolstr_impl --- CHANGELOG.md | 1 + Cargo.lock | 18 +++++++++++++++++- README.md | 1 + ts-rs/Cargo.toml | 8 ++++---- ts-rs/src/lib.rs | 6 +++++- ts-rs/tests/integration/impl_primitive.rs | 15 +++++++++++++-- 6 files changed, 41 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 9ac7fe9c..66f4d4e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - The `bson-uuid-impl` feature now supports `bson::oid::ObjectId` as well ([#340](https://github.com/Aleph-Alpha/ts-rs/pull/340)) - Allow multile types to have the same `#[ts(export_to = "...")]` attribute and be exported to the same file ([#316](https://github.com/Aleph-Alpha/ts-rs/pull/316)) - Add support for types from `smol_str` behind cargo feature `smol_str-impl` +- Add support for types from `rust_decimal` behind cargo feature `rust_decimal-impl` ### Fixes diff --git a/Cargo.lock b/Cargo.lock index 002a63e1..da92da88 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -61,6 +61,12 @@ version = "1.0.86" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da" +[[package]] +name = "arrayvec" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7c02d123df017efcdfbd739ef81735b36c5ba83ec3c59c80a9d7ecc718f92e50" + [[package]] name = "ast_node" version = "0.9.8" @@ -105,7 +111,6 @@ dependencies = [ "num-bigint", "num-integer", "num-traits", - "serde", ] [[package]] @@ -755,6 +760,16 @@ version = "0.8.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" +[[package]] +name = "rust_decimal" +version = "1.36.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b082d80e3e3cc52b2ed634388d436fe1f4de6af5786cc2de9ba9737527bdf555" +dependencies = [ + "arrayvec", + "num-traits", +] + [[package]] name = "rustc-hash" version = "1.1.0" @@ -1178,6 +1193,7 @@ dependencies = [ "indexmap", "lazy_static", "ordered-float", + "rust_decimal", "semver", "serde", "serde_json", diff --git a/README.md b/README.md index b840f463..131d7a03 100644 --- a/README.md +++ b/README.md @@ -87,6 +87,7 @@ When running `cargo test`, the TypeScript bindings will be exported to the file | heapless-impl | Implement `TS` for types from *heapless* | | semver-impl | Implement `TS` for types from *semver* | | smol_str-impl | Implement `TS` for types from *smol_str* | +| rust_decimal-impl | Implement `TS` for types from *rust_decimal* |
diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index 8da5e7c5..459820a7 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -20,6 +20,7 @@ rust-version = "1.63.0" [features] chrono-impl = ["chrono"] bigdecimal-impl = ["bigdecimal"] +rust_decimal-impl = ["rust_decimal"] uuid-impl = ["uuid"] bson-uuid-impl = ["bson"] bytes-impl = ["bytes"] @@ -31,7 +32,7 @@ indexmap-impl = ["indexmap"] ordered-float-impl = ["ordered-float"] heapless-impl = ["heapless"] semver-impl = ["semver"] -smolstr-impl = ["smol_str"] +smol_str-impl = ["smol_str"] serde-json-impl = ["serde_json"] no-serde-warnings = ["ts-rs-macros/no-serde-warnings"] import-esm = [] @@ -46,9 +47,8 @@ heapless = { version = ">= 0.7, < 0.9", optional = true } ts-rs-macros = { version = "=9.0.1", path = "../macros" } dprint-plugin-typescript = { version = "0.90", optional = true } chrono = { version = "0.4", optional = true } -bigdecimal = { version = ">= 0.0.13, < 0.5", features = [ - "serde", -], optional = true } +bigdecimal = { version = ">= 0.0.13, < 0.5", optional = true } +rust_decimal = { version = "1",default-features = false, optional = true } uuid = { version = "1", optional = true } bson = { version = "2", optional = true } bytes = { version = "1", optional = true } diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 5e1ccfdc..b7167fec 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -85,6 +85,7 @@ //! | heapless-impl | Implement `TS` for types from *heapless* | //! | semver-impl | Implement `TS` for types from *semver* | //! | smol_str-impl | Implement `TS` for types from *smol_str* | +//! | rust_decimal-impl | Implement `TS` for types from *rust_decimal* | //! //!
//! @@ -995,7 +996,10 @@ impl_tuples!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10); #[cfg(feature = "bigdecimal-impl")] impl_primitives! { bigdecimal::BigDecimal => "string" } -#[cfg(feature = "smolstr-impl")] +#[cfg(feature = "rust_decimal-impl")] +impl_primitives! { rust_decimal::Decimal => "string" } + +#[cfg(feature = "smol_str-impl")] impl_primitives! { smol_str::SmolStr => "string" } #[cfg(feature = "uuid-impl")] diff --git a/ts-rs/tests/integration/impl_primitive.rs b/ts-rs/tests/integration/impl_primitive.rs index 893439bf..c7708453 100644 --- a/ts-rs/tests/integration/impl_primitive.rs +++ b/ts-rs/tests/integration/impl_primitive.rs @@ -10,8 +10,19 @@ fn impl_primitive_bigdecimal() { ::inline() ) } - -#[cfg(feature = "smolstr-impl")] +#[cfg(feature = "rust_decimal-impl")] +#[test] +fn impl_primitive_rustdecimal() { + assert_eq!( + ::name(), + ::name() + ); + assert_eq!( + ::inline(), + ::inline() + ) +} +#[cfg(feature = "smol_str-impl")] #[test] fn impl_primitive_smolstr() { assert_eq!(