From c042fbaac803ae0e82f36a285a2924cf9984c81d Mon Sep 17 00:00:00 2001 From: Tom Karwowski Date: Thu, 1 Feb 2024 18:33:42 +0100 Subject: [PATCH] feat: impl JsonTypdef for Url (behind a feature flag) --- Cargo.lock | 67 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 ++++ src/trait.rs | 6 +++++ 3 files changed, 77 insertions(+) diff --git a/Cargo.lock b/Cargo.lock index e31bef0..b592792 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -19,12 +19,31 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +[[package]] +name = "form_urlencoded" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" +dependencies = [ + "percent-encoding", +] + [[package]] name = "glob" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" +[[package]] +name = "idna" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +dependencies = [ + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "itertools" version = "0.10.5" @@ -49,6 +68,7 @@ dependencies = [ "serde_json", "thiserror", "trybuild", + "url", ] [[package]] @@ -70,6 +90,12 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6f61fba1741ea2b3d6a1e3178721804bb716a68a6aeba1149b5d52e3d464ea66" +[[package]] +name = "percent-encoding" +version = "2.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" + [[package]] name = "proc-macro-error" version = "1.0.4" @@ -200,6 +226,21 @@ dependencies = [ "syn", ] +[[package]] +name = "tinyvec" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87cc5ceb3875bb20c2890005a4e226a4651264a5c75edb2421b52861a0a0cb50" +dependencies = [ + "tinyvec_macros", +] + +[[package]] +name = "tinyvec_macros" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" + [[package]] name = "toml" version = "0.5.10" @@ -224,12 +265,38 @@ dependencies = [ "toml", ] +[[package]] +name = "unicode-bidi" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" + [[package]] name = "unicode-ident" version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "84a22b9f218b40614adcb3f4ff08b703773ad44fa9423e4e0d346d5db86e4ebc" +[[package]] +name = "unicode-normalization" +version = "0.1.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c5713f0fc4b5db668a2ac63cdb7bb4469d8c9fed047b1d0292cc7b0ce2ba921" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "url" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "31e6302e3bb753d46e83516cae55ae196fc0c309407cf11ab35cc51a4c2a4633" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", +] + [[package]] name = "version_check" version = "0.9.4" diff --git a/Cargo.toml b/Cargo.toml index 907f391..f272b50 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -12,11 +12,15 @@ documentation = "https://docs.rs/jtd-derive" categories = ["encoding"] keywords = ["schema", "codegen", "json"] +[features] +url = ["dep:url"] + [dependencies] jtd-derive-macros = { version = "=0.1.3", path = "macros" } serde = { version = "1.0.115", features = ["derive"] } serde_json = "1.0.50" thiserror = "1.0.3" +url = { version = "2", optional = true } [dev-dependencies] trybuild = "1.0.49" diff --git a/src/trait.rs b/src/trait.rs index 3541dec..b43d32b 100644 --- a/src/trait.rs +++ b/src/trait.rs @@ -131,6 +131,12 @@ impl_wrappers! { std::net => SocketAddrV6 => String, std::path => Path => String + +} + +#[cfg(feature = "url")] +impl_wrappers!{ + url => Url => String } impl JsonTypedef for std::path::PathBuf {