diff --git a/Cargo.lock b/Cargo.lock index 972cdfe..c6d5562 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -191,6 +191,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" @@ -326,7 +341,7 @@ version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6a989bd2fd12136080f7825ff410d9239ce84a2a639487fc9d924ee42e2fb84f" dependencies = [ - "compact_str", + "compact_str 0.7.1", "garde_derive", "once_cell", "regex", @@ -837,6 +852,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 49b7092..4084068 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" @@ -54,6 +55,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;