Skip to content

Commit

Permalink
support for rust_decimal::Decimal
Browse files Browse the repository at this point in the history
rename rustdecimal_impl and smolstr_impl
  • Loading branch information
corvusrabus committed Sep 7, 2024
1 parent 7577aca commit 5700cb0
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

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.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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* |

<br/>

Expand Down
8 changes: 4 additions & 4 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"]
rust_decimal-impl = ["rust_decimal"]
uuid-impl = ["uuid"]
bson-uuid-impl = ["bson"]
bytes-impl = ["bytes"]
Expand All @@ -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 = []
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 @@ -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* |
//!
//! <br/>
//!
Expand Down Expand Up @@ -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")]
Expand Down
15 changes: 13 additions & 2 deletions ts-rs/tests/integration/impl_primitive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,19 @@ fn impl_primitive_bigdecimal() {
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "smolstr-impl")]
#[cfg(feature = "rust_decimal-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 = "smol_str-impl")]
#[test]
fn impl_primitive_smolstr() {
assert_eq!(
Expand Down

0 comments on commit 5700cb0

Please sign in to comment.