From 92ad6c80117b68339141abd840552afad4325c3c Mon Sep 17 00:00:00 2001 From: Aleksandr Date: Sat, 26 Oct 2024 19:45:21 +0300 Subject: [PATCH] feat: implement `compact_str` --- Cargo.lock | 17 ++++++++++++++++- schemars/Cargo.toml | 2 ++ schemars/src/json_schema_impls/mod.rs | 3 +++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index 0f076208..bdd6b6e6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -201,6 +201,20 @@ dependencies = [ "static_assertions", ] +[[package]] +name = "compact_str" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6050c3a16ddab2e412160b31f2c871015704239bca62f72f6e5f0be631d3f644" +dependencies = [ + "castaway", + "cfg-if", + "itoa", + "rustversion", + "ryu", + "static_assertions", +] + [[package]] name = "darling" version = "0.20.10" @@ -313,7 +327,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 +791,7 @@ dependencies = [ "bigdecimal", "bytes", "chrono", + "compact_str 0.8.0", "dyn-clone", "either", "garde", diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 384f3eae..2a87dc07 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_str = { version = "0.8.0", optional = true } [dev-dependencies] pretty_assertions = "1.2.1" @@ -78,6 +79,7 @@ raw_value = ["serde_json/raw_value"] # For internal/CI use only _ui_test = [] +compact_str = ["dep:compact_str"] [[test]] name = "ui" diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index cbe1a075..0299ac2f 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_str")] +forward_impl!(compact_str::CompactString => alloc::string::String); + #[cfg(feature = "url2")] mod url2;