diff --git a/Cargo.lock b/Cargo.lock index 92ed468a..9f93b108 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,6 +59,21 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2bd12c1caf447e69cd4528f47f94d203fd2582878ecb9e9465484c4148a8223" +[[package]] +name = "castaway" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0abae9be0aaf9ea96a3b1b8b1b55c602ca751eba1b1500220cea4ecbafe7c0d5" +dependencies = [ + "rustversion", +] + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + [[package]] name = "chrono" version = "0.4.31" @@ -68,6 +83,20 @@ dependencies = [ "num-traits", ] +[[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.3" @@ -310,6 +339,12 @@ dependencies = [ "num-traits", ] +[[package]] +name = "rustversion" +version = "1.0.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" + [[package]] name = "ryu" version = "1.0.15" @@ -326,6 +361,7 @@ dependencies = [ "bigdecimal 0.4.2", "bytes", "chrono", + "compact_str", "dyn-clone", "either", "enumset", @@ -422,6 +458,12 @@ dependencies = [ "serde", ] +[[package]] +name = "static_assertions" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" + [[package]] name = "syn" version = "2.0.38" diff --git a/schemars/Cargo.toml b/schemars/Cargo.toml index 264a5c59..ba97fed8 100644 --- a/schemars/Cargo.toml +++ b/schemars/Cargo.toml @@ -35,6 +35,7 @@ bigdecimal03 = { version = "0.3", default-features = false, optional = true, pac bigdecimal04 = { version = "0.4", default-features = false, optional = true, package = "bigdecimal" } enumset = { version = "1.0", optional = true } smol_str = { version = "0.1.17", optional = true } +compact_str = { version = "0.8.0", optional = true } semver = { version = "1.0.9", features = ["serde"], optional = true } [dev-dependencies] diff --git a/schemars/src/json_schema_impls/compact_str.rs b/schemars/src/json_schema_impls/compact_str.rs new file mode 100644 index 00000000..8bf88e02 --- /dev/null +++ b/schemars/src/json_schema_impls/compact_str.rs @@ -0,0 +1,6 @@ +use crate::gen::SchemaGenerator; +use crate::schema::*; +use crate::JsonSchema; +use compact_str::CompactString; + +forward_impl!(CompactString => String); diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index 0c548eb3..e9e2fcb2 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -50,6 +50,8 @@ mod atomic; mod bytes; #[cfg(feature = "chrono")] mod chrono; +#[cfg(feature = "compact_str")] +mod compact_str; mod core; #[cfg(any( feature = "rust_decimal", diff --git a/schemars/tests/compact_str.rs b/schemars/tests/compact_str.rs new file mode 100644 index 00000000..61a24c87 --- /dev/null +++ b/schemars/tests/compact_str.rs @@ -0,0 +1,8 @@ +mod util; +use compact_str::CompactString; +use util::*; + +#[test] +fn smol_str() -> TestResult { + test_default_generated_schema::("compact_str") +} diff --git a/schemars/tests/expected/compact_str.json b/schemars/tests/expected/compact_str.json new file mode 100644 index 00000000..42f099a3 --- /dev/null +++ b/schemars/tests/expected/compact_str.json @@ -0,0 +1,5 @@ +{ + "$schema": "http://json-schema.org/draft-07/schema#", + "title": "String", + "type": "string" +} \ No newline at end of file