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

feat: impl for semver::Version #176

Merged
merged 6 commits into from
Jan 26, 2024
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
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ When running `cargo test`, the TypeScript bindings will be exported to the file

Implement `TS` for `Vec` from heapless

- `semver-impl`
Implement `TS` for `Version` from semver

- `no-serde-warnings`

When `serde-compat` is enabled, warnings are printed during build if unsupported serde
Expand Down
2 changes: 2 additions & 0 deletions ts-rs/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ default = ["serde-compat"]
indexmap-impl = ["indexmap"]
ordered-float-impl = ["ordered-float"]
heapless-impl = ["heapless"]
semver-impl = ["semver"]
no-serde-warnings = ["ts-rs-macros/no-serde-warnings"]
import-esm = []

Expand All @@ -48,6 +49,7 @@ uuid = { version = "1.1.2", optional = true }
bson = { version = "2.2.0", optional = true }
bytes = { version = "1.0", optional = true }
url = { version = "2.3", optional = true }
semver = { version = "1.0.21", optional = true }
thiserror = "1"
indexmap = { version = "2.0.0", optional = true }
ordered-float = { version = "3.0.0", optional = true }
6 changes: 6 additions & 0 deletions ts-rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@
//! - `heapless-impl`
//!
//! Implement `TS` for `Vec` from heapless
//!
//! - `semver-impl`
//! Implement `TS` for `Version` from semver
//!
//! - `no-serde-warnings`
//!
Expand Down Expand Up @@ -655,6 +658,9 @@ impl_shadow!(as HashMap<K, V>: impl<K: TS, V: TS> TS for indexmap::IndexMap<K, V
#[cfg(feature = "heapless-impl")]
impl_shadow!(as Vec<T>: impl<T: TS, const N: usize> TS for heapless::Vec<T, N>);

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

#[cfg(feature = "bytes-impl")]
mod bytes {
use super::TS;
Expand Down
18 changes: 18 additions & 0 deletions ts-rs/tests/semver.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#![cfg(feature = "semver-impl")]

use semver::Version;
use ts_rs::TS;

#[test]
fn semver() {
#[derive(TS)]
struct Semver {
#[allow(dead_code)]
version: Version,
}

assert_eq!(
Semver::decl(),
"type Semver = { version: string, }"
)
}
Loading