Skip to content

Commit

Permalink
feat: Adds optional ulid Type
Browse files Browse the repository at this point in the history
Testing: `cargo test --features ulid,typescript --test integration_tests -- ulid::ulid`
  • Loading branch information
beanow-at-crabnebula committed Oct 12, 2023
1 parent 4dea4d5 commit 4b59a0b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ required-features = ["export", "typescript"]

# Run `node ./.github/features.js` to update the docs
[features]
default = []
default = ["ulid", "typescript"]

##! Internal Features
## Support for exporting the types of Rust functions.
Expand Down Expand Up @@ -69,6 +69,8 @@ tauri = ["dep:tauri"]
#! External types
## [uuid](https://docs.rs/uuid) crate
uuid = ["dep:uuid"]
## [uuid](https://docs.rs/ulid) crate
ulid = ["dep:ulid"]
## [chrono](https://docs.rs/chrono) crate
chrono = ["dep:chrono"]
## [time](https://docs.rs/time) crate
Expand Down Expand Up @@ -106,6 +108,7 @@ serde = { version = "1.0.183", optional = true, default-features = false, featur
serde_json = { version = "1.0.104", optional = true, default-features = false, features = ["std"] }
serde_yaml = { version = "0.9.25", optional = true, default-features = false, features = [] }
toml = { version = "0.7.6", optional = true, default-features = false }
ulid = { version = "1.1.0", optional = true, default-features = false, features = [] }
uuid = { version = "1.4.1", optional = true, default-features = false, features = [] }
chrono = { version = "0.4.26", optional = true, default-features = false, features = ["clock"] }
time = { version = "0.3.25", optional = true, default-features = false, features = [] }
Expand Down
1 change: 1 addition & 0 deletions src/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ Compatability

External types

- `ulid` - [ulid](https://docs.rs/ulid) crate
- `uuid` - [uuid](https://docs.rs/uuid) crate
- `chrono` - [chrono](https://docs.rs/chrono) crate
- `time` - [time](https://docs.rs/time) crate
Expand Down
3 changes: 3 additions & 0 deletions src/type/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,9 @@ const _: () = {
}
};

#[cfg(feature = "ulid")]
impl_as!(ulid::Ulid as String);

#[cfg(feature = "uuid")]
impl_as!(
uuid::Uuid as String
Expand Down
3 changes: 3 additions & 0 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ pub mod ts;
mod ts_rs;
mod ty_override;

#[cfg(all(feature = "ulid", feature = "typescript"))]
mod ulid;

#[test]
fn test_compile_errors() {
let t = trybuild::TestCases::new();
Expand Down
13 changes: 13 additions & 0 deletions tests/ulid.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use specta::Type;

use crate::ts::assert_ts;

#[derive(Type)]
#[specta(export = false)]
struct ExampleId(pub ulid::Ulid);

#[test]
fn ulid() {
assert_ts!(ulid::Ulid, "string");
assert_ts!(ExampleId, "string");
}

0 comments on commit 4b59a0b

Please sign in to comment.