From 52a67fff57732dd993745b060757ff481eb6813e Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Sat, 18 Jan 2025 15:26:47 +0300 Subject: [PATCH 1/2] add support for `compact_str` crate --- Cargo.lock | 18 +++++++++++++++++- schemars/Cargo.toml | 2 ++ schemars/src/json_schema_impls/mod.rs | 3 +++ schemars/tests/integration/compact_str.rs | 11 +++++++++++ schemars/tests/integration/main.rs | 2 ++ 5 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 schemars/tests/integration/compact_str.rs diff --git a/Cargo.lock b/Cargo.lock index 0f30998..d574a44 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,6 +201,21 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "compact_str" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b79c4069c6cad78e2e0cdfcbd26275770669fb39fd308a752dc110e83b9af32" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "serde", + "static_assertions", +] + [[package]] name = "darling" version = "0.20.10" @@ -313,7 +328,7 @@ name = "garde" version = "0.20.0" source = "git+https://github.com/jprochazk/garde.git?rev=be00ddddf8de14530ee890ccfdbaf0b13fb32852#be00ddddf8de14530ee890ccfdbaf0b13fb32852" dependencies = [ - "compact_str", + "compact_str 0.7.1", "garde_derive", "once_cell", "regex", @@ -777,6 +792,7 @@ dependencies = [ "bigdecimal", "bytes", "chrono", + "compact_str 0.8.1", "dyn-clone", "either", "garde", diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 96232ea..a3aa7b6 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -32,6 +32,7 @@ smallvec1 = { version = "1.0", default-features = false, optional = true, packag smol_str02 = { version = "0.2.1", default-features = false, optional = true, package = "smol_str" } url2 = { version = "2.0", default-features = false, optional = true, package = "url" } uuid1 = { version = "1.0", default-features = false, optional = true, package = "uuid" } +compact_str08 = { version = "0.8", default-features = false, optional = true, package = "compact_str" } [dev-dependencies] pretty_assertions = "1.2.1" @@ -55,6 +56,7 @@ rust_decimal1 = { version = "1", default-features = false, features = ["serde"], semver1 = { version = "1.0.9", default-features = false, features = ["serde"], package = "semver" } smallvec1 = { version = "1.0", default-features = false, features = ["serde"], package = "smallvec" } smol_str02 = { version = "0.2.1", default-features = false, features = ["serde"], package = "smol_str" } +compact_str08 = { version = "0.8", default-features = false, features = ["serde"], package = "compact_str" } url2 = { version = "2.0", default-features = false, features = ["serde"], package = "url" } uuid1 = { version = "1.0", default-features = false, features = ["serde"], package = "uuid" } diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index cbe1a07..c4e4c51 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -83,6 +83,9 @@ forward_impl!(( crate::JsonSchema for smallvec1::SmallVec alloc::string::String); +#[cfg(feature = "compact_str08")] +forward_impl!(compact_str08::CompactString => alloc::string::String); + #[cfg(feature = "url2")] mod url2; diff --git a/schemars/tests/integration/compact_str.rs b/schemars/tests/integration/compact_str.rs new file mode 100644 index 0000000..a40db1e --- /dev/null +++ b/schemars/tests/integration/compact_str.rs @@ -0,0 +1,11 @@ +use compact_str08::CompactString; + +use crate::prelude::*; + +#[test] +fn compact_str() { + test!(CompactString) + .assert_identical::() + .assert_allows_ser_roundtrip(["".into(), "test".into()]) + .assert_matches_de_roundtrip(arbitrary_values()); +} diff --git a/schemars/tests/integration/main.rs b/schemars/tests/integration/main.rs index eb44526..0d9da89 100644 --- a/schemars/tests/integration/main.rs +++ b/schemars/tests/integration/main.rs @@ -41,6 +41,8 @@ mod skip; mod smallvec; #[cfg(feature = "smol_str02")] mod smol_str; +#[cfg(feature = "compact_str08")] +mod compact_str; mod std_types; mod structs; mod transform; From cd26406fa95e7984f62700d4ea22765e81b2a1f3 Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Sat, 15 Feb 2025 23:01:42 +0300 Subject: [PATCH 2/2] feat: support hashbrown015 --- Cargo.lock | 12 +++++++++++- schemars/Cargo.toml | 2 ++ schemars/src/json_schema_impls/mod.rs | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index d574a44..f0abe4a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -372,6 +372,15 @@ version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" +[[package]] +name = "hashbrown" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +dependencies = [ + "serde", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -395,7 +404,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" dependencies = [ "equivalent", - "hashbrown", + "hashbrown 0.14.5", "serde", ] @@ -796,6 +805,7 @@ dependencies = [ "dyn-clone", "either", "garde", + "hashbrown 0.15.2", "indexmap", "jsonschema", "pretty_assertions", diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index a3aa7b6..fb33fd1 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -20,6 +20,7 @@ dyn-clone = "1.0" ref-cast = "1.0.22" # optional dependencies +hashbrown015 = { version = "0.15", default-features = false, optional = true, package = "hashbrown" } arrayvec07 = { version = "0.7", default-features = false, optional = true, package = "arrayvec" } bigdecimal04 = { version = "0.4", default-features = false, optional = true, package = "bigdecimal" } bytes1 = { version = "1.0", default-features = false, optional = true, package = "bytes" } @@ -46,6 +47,7 @@ garde = { git = "https://github.com/jprochazk/garde.git", rev = "be00ddddf8de145 validator = { version = "0.18.1", features = ["derive"] } regex = { version = "1.10.6", default-features = false } +hashbrown015 = { version = "0.15", default-features = false, features = ["serde"], package = "hashbrown" } arrayvec07 = { version = "0.7", default-features = false, features = ["serde"], package = "arrayvec"} bigdecimal04 = { version = "0.4", default-features = false, features = ["serde"], package = "bigdecimal" } bytes1 = { version = "1.0", default-features = false, features = ["serde"], package = "bytes" } diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index c4e4c51..0b5e029 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -86,6 +86,9 @@ forward_impl!(smol_str02::SmolStr => alloc::string::String); #[cfg(feature = "compact_str08")] forward_impl!(compact_str08::CompactString => alloc::string::String); +#[cfg(feature = "hashbrown015")] +forward_impl!(( crate::JsonSchema for hashbrown015::HashMap) => std::collections::HashMap); + #[cfg(feature = "url2")] mod url2;