diff --git a/example/Cargo.toml b/example/Cargo.toml index 85d6b9d..42867a1 100644 --- a/example/Cargo.toml +++ b/example/Cargo.toml @@ -5,6 +5,7 @@ authors = ["Moritz Bischof "] edition = "2018" [dependencies] -ts-rs = { path = "../ts-rs", features = ["serde-compat"] } +ts-rs = { path = "../ts-rs", features = ["serde-compat", "uuid-impl"] } serde = { version = "1", features = ["derive", "rc"] } chrono = { version = "0.4", features = ["serde"] } +uuid = { version = "0.8.2", features = ["v4", "serde"] } diff --git a/example/src/lib.rs b/example/src/lib.rs index 4cb2e6f..4783c5b 100644 --- a/example/src/lib.rs +++ b/example/src/lib.rs @@ -5,6 +5,7 @@ use std::{collections::BTreeSet, rc::Rc}; use chrono::NaiveDateTime; use serde::Serialize; use ts_rs::{export, TS}; +use uuid::Uuid; #[derive(Serialize, TS)] #[ts(rename_all = "lowercase")] @@ -32,6 +33,7 @@ struct User { family: Vec, #[ts(inline)] gender: Gender, + token: Uuid, #[ts(type = "string")] created_at: NaiveDateTime, } diff --git a/ts-rs/Cargo.toml b/ts-rs/Cargo.toml index e3d75fe..4b88b39 100644 --- a/ts-rs/Cargo.toml +++ b/ts-rs/Cargo.toml @@ -11,6 +11,7 @@ repository = "https://github.com/Aleph-Alpha/ts-rs" [features] chrono-impl = ["chrono"] bigdecimal-impl = ["bigdecimal"] +uuid-impl = ["uuid"] serde-compat = ["ts-rs-macros/serde-compat"] [dev-dependencies] @@ -20,4 +21,5 @@ serde = { version = "1.0", features = ["derive"] } ts-rs-macros = { version = "4.0.0", path = "../macros" } dprint-plugin-typescript = { version = "0.43" } chrono = { version = "0.4.19", optional = true } -bigdecimal = {version = "0.1.2", features=["serde"], optional = true} \ No newline at end of file +bigdecimal = {version = "0.1.2", features=["serde"], optional = true} +uuid = { version = "0.8.2", optional = true } \ No newline at end of file diff --git a/ts-rs/src/lib.rs b/ts-rs/src/lib.rs index 3c1c8f7..7ef0690 100644 --- a/ts-rs/src/lib.rs +++ b/ts-rs/src/lib.rs @@ -252,11 +252,9 @@ impl_primitives! { #[cfg(feature = "chrono-impl")] mod chrono_impls { - use std::any::TypeId; - - use chrono::{Date, DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone}; - use super::TS; + use chrono::{Date, DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone}; + use std::any::TypeId; impl_primitives! { NaiveDateTime, NaiveDate, NaiveTime => "string" @@ -304,6 +302,11 @@ impl_primitives! { bigdecimal::BigDecimal => "string" } +#[cfg(feature = "uuid-impl")] +impl_primitives! { + uuid::Uuid => "string" +} + impl_tuples!(T1, T2, T3, T4, T5, T6, T7, T8, T9, T10); impl_proxy!(impl TS for Box); impl_proxy!(impl TS for std::sync::Arc);