Skip to content

Commit

Permalink
support for rust_decimal::Decimal
Browse files Browse the repository at this point in the history
  • Loading branch information
corvusrabus committed Sep 7, 2024
1 parent 7577aca commit 82acfec
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

- 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 `smol_str` behind cargo feature `smolstr-impl`
- Add support for types from `rust_decimal` behind cargo feature `rustdecimal-impl`

### Fixes

Expand Down
18 changes: 17 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ When running `cargo test`, the TypeScript bindings will be exported to the file
| ordered-float-impl | Implement `TS` for types from *ordered_float* |
| 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* |
| smolstr-impl | Implement `TS` for types from *smol_str* |
| rustdecimal-impl | Implement `TS` for types from *rust_decimal* |

<br/>

Expand Down
6 changes: 3 additions & 3 deletions ts-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ rust-version = "1.63.0"
[features]
chrono-impl = ["chrono"]
bigdecimal-impl = ["bigdecimal"]
rustdecimal-impl = ["rust_decimal"]
uuid-impl = ["uuid"]
bson-uuid-impl = ["bson"]
bytes-impl = ["bytes"]
Expand All @@ -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 }
Expand Down
6 changes: 5 additions & 1 deletion ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@
//! | ordered-float-impl | Implement `TS` for types from *ordered_float* |
//! | 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* |
//! | smolstr-impl | Implement `TS` for types from *smol_str* |
//! | rustdecimal-impl | Implement `TS` for types from *rust_decimal* |
//!
//! <br/>
//!
Expand Down Expand Up @@ -995,6 +996,9 @@ impl_tuples!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10);
#[cfg(feature = "bigdecimal-impl")]
impl_primitives! { bigdecimal::BigDecimal => "string" }

#[cfg(feature = "rustdecimal-impl")]
impl_primitives! { rust_decimal::Decimal => "string" }

#[cfg(feature = "smolstr-impl")]
impl_primitives! { smol_str::SmolStr => "string" }

Expand Down
13 changes: 12 additions & 1 deletion ts-rs/tests/integration/impl_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,18 @@ fn impl_primitive_bigdecimal() {
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "rustdecimal-impl")]
#[test]
fn impl_primitive_rustdecimal() {
assert_eq!(
<rust_decimal::Decimal as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<rust_decimal::Decimal as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}
#[cfg(feature = "smolstr-impl")]
#[test]
fn impl_primitive_smolstr() {
Expand Down

0 comments on commit 82acfec

Please sign in to comment.