Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: support smol_str #350

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,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`

### Fixes

Expand Down
26 changes: 26 additions & 0 deletions 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 @@ -86,6 +86,7 @@ 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* |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, the feature is called smol_str-impl, but it's actually smolstr-impl in Cargo.toml.

I'd prefer smol_str-impl everywhere, since that matches the <crate name>-impl naming scheme we've got going on here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure thing. I'll add it to this one #351


<br/>

Expand Down
2 changes: 2 additions & 0 deletions ts-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ indexmap-impl = ["indexmap"]
ordered-float-impl = ["ordered-float"]
heapless-impl = ["heapless"]
semver-impl = ["semver"]
smolstr-impl = ["smol_str"]
serde-json-impl = ["serde_json"]
no-serde-warnings = ["ts-rs-macros/no-serde-warnings"]
import-esm = []
Expand All @@ -53,6 +54,7 @@ bson = { version = "2", optional = true }
bytes = { version = "1", optional = true }
url = { version = "2", optional = true }
semver = { version = "1", optional = true }
smol_str = { version = "0.3", optional = true }
thiserror = "1"
indexmap = { version = "2", optional = true }
ordered-float = { version = ">= 3, < 5", optional = true }
Expand Down
4 changes: 4 additions & 0 deletions ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
//! | 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* |
//!
//! <br/>
//!
Expand Down Expand Up @@ -994,6 +995,9 @@ 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")]
impl_primitives! { smol_str::SmolStr => "string" }

#[cfg(feature = "uuid-impl")]
impl_primitives! { uuid::Uuid => "string" }

Expand Down
106 changes: 106 additions & 0 deletions ts-rs/tests/integration/impl_primitive.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
#[cfg(feature = "bigdecimal-impl")]
#[test]
fn impl_primitive_bigdecimal() {
assert_eq!(
<bigdecimal::BigDecimal as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<bigdecimal::BigDecimal as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "smolstr-impl")]
#[test]
fn impl_primitive_smolstr() {
assert_eq!(
<smol_str::SmolStr as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<smol_str::SmolStr as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "uuid-impl")]
#[test]
fn impl_primitive_uuid() {
assert_eq!(
<uuid::Uuid as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<uuid::Uuid as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "url-impl")]
#[test]
fn impl_primitive_url() {
assert_eq!(
<url::Url as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<url::Url as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "ordered-float-impl")]
#[test]
fn impl_primitive_order_float() {
assert_eq!(
<ordered_float::OrderedFloat<f64> as ts_rs::TS>::name(),
<f64 as ts_rs::TS>::name()
);
assert_eq!(
<ordered_float::OrderedFloat<f64> as ts_rs::TS>::inline(),
<f64 as ts_rs::TS>::inline()
);
assert_eq!(
<ordered_float::OrderedFloat<f32> as ts_rs::TS>::name(),
<f32 as ts_rs::TS>::name()
);
assert_eq!(
<ordered_float::OrderedFloat<f32> as ts_rs::TS>::inline(),
<f32 as ts_rs::TS>::inline()
)
}

#[cfg(feature = "bson-uuid-impl")]
#[test]
fn impl_primitive_bson_uuid() {
assert_eq!(
<bson::oid::ObjectId as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<bson::oid::ObjectId as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
);
assert_eq!(
<bson::Uuid as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<bson::Uuid as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}

#[cfg(feature = "semver-impl")]
#[test]
fn impl_primitive_semver() {
assert_eq!(
<semver::Version as ts_rs::TS>::name(),
<String as ts_rs::TS>::name()
);
assert_eq!(
<semver::Version as ts_rs::TS>::inline(),
<String as ts_rs::TS>::inline()
)
}
1 change: 1 addition & 0 deletions ts-rs/tests/integration/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ mod generics;
mod generics_flatten;
mod hashmap;
mod hashset;
mod impl_primitive;
mod imports;
mod indexmap;
mod infer_as;
Expand Down