Skip to content

Commit

Permalink
add support for compact_str crate
Browse files Browse the repository at this point in the history
  • Loading branch information
nerodono committed Jul 25, 2024
1 parent e0c2c31 commit 25cb722
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 0 deletions.
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions schemars/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
6 changes: 6 additions & 0 deletions schemars/src/json_schema_impls/compact_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
use crate::gen::SchemaGenerator;
use crate::schema::*;
use crate::JsonSchema;
use compact_str::CompactString;

forward_impl!(CompactString => String);
2 changes: 2 additions & 0 deletions schemars/src/json_schema_impls/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 8 additions & 0 deletions schemars/tests/compact_str.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
mod util;
use compact_str::CompactString;
use util::*;

#[test]
fn smol_str() -> TestResult {
test_default_generated_schema::<CompactString>("compact_str")
}
5 changes: 5 additions & 0 deletions schemars/tests/expected/compact_str.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "String",
"type": "string"
}

0 comments on commit 25cb722

Please sign in to comment.