Aleph-Alpha / ts-rs

Generate TypeScript bindings from Rust types
MIT License
1.08k stars 107 forks source link

feat(impls): add rust_decimal::Decimal impl #273

Closed seanpianka closed 4 months ago

seanpianka commented 6 months ago

Goal

Provide a serde-based implementation of TS for rust_decimal::Decimal Closes #272

Changes

Derive an implementation for rust_decimal::Decimal using feature flag serde-with-str.

Checklist

escritorio-gustavo commented 6 months ago

Hey, thanks for the PR! Please check out the Contributing guide for instructions on how to update the README.

Edit: I see the link in the PR template is incorrectly pointing at the CHANGELOG file instead of CONTRIBUTING, sorry about that, it's already been fixed, both in the template and in this PR's description

NyxCode commented 6 months ago

I'm a bit confused by rust-decimal in general. Their usage of features seems a bit odd to me (though we're abusing them similarly I guess).

If we want support rust-decimal going forward, I think we need to seamlessly support all these modes - and I'm not sure that's easily possible.

Re-exposing all features of rust_decimal, for example, doesn't seem great.
rust_decimal already has feature gates for a wide variety of libraries, so maybe it'd be worth a shot to open a PR there. In the rust_decimal crate, this could be implemented nicely using #[cfg(feature = "..")] annotations.

NyxCode commented 4 months ago

Closing this for now. I think we established that we can't support this properly. Either rust_decimal implements TS behind a feature-flag, or users will have to use #[ts(as = ..)] or #[ts(type = "..")].