diff --git a/schemars/src/json_schema_impls/deref.rs b/schemars/src/json_schema_impls/deref.rs deleted file mode 100644 index d836090..0000000 --- a/schemars/src/json_schema_impls/deref.rs +++ /dev/null @@ -1,39 +0,0 @@ -use crate::gen::SchemaGenerator; -use crate::schema::Schema; -use crate::JsonSchema; - -macro_rules! deref_impl { - ($($desc:tt)+) => { - impl $($desc)+ - where - T: ?Sized + JsonSchema, - { - fn is_referenceable() -> bool { - T::is_referenceable() - } - - fn schema_name() -> String { - T::schema_name() - } - - fn json_schema(gen: &mut SchemaGenerator) -> Schema { - T::json_schema(gen) - } - - fn json_schema_optional(gen: &mut SchemaGenerator) -> Schema { - T::json_schema_optional(gen) - } - } - }; -} - -deref_impl!(<'a, T> JsonSchema for &'a T); -deref_impl!(<'a, T> JsonSchema for &'a mut T); -deref_impl!( JsonSchema for Box); -deref_impl!( JsonSchema for std::rc::Rc); -deref_impl!( JsonSchema for std::sync::Arc); -deref_impl!( JsonSchema for std::sync::Mutex); -deref_impl!( JsonSchema for std::sync::RwLock); -deref_impl!( JsonSchema for std::cell::Cell); -deref_impl!( JsonSchema for std::cell::RefCell); -deref_impl!(<'a, T: ToOwned> JsonSchema for std::borrow::Cow<'a, T>); diff --git a/schemars/src/json_schema_impls/mod.rs b/schemars/src/json_schema_impls/mod.rs index 548e942..f753d5d 100644 --- a/schemars/src/json_schema_impls/mod.rs +++ b/schemars/src/json_schema_impls/mod.rs @@ -10,7 +10,7 @@ mod array; #[cfg(feature = "chrono")] mod chrono; mod core; -mod deref; +mod wrapper; mod maps; mod primitives; mod sequences; diff --git a/schemars/src/json_schema_impls/wrapper.rs b/schemars/src/json_schema_impls/wrapper.rs new file mode 100644 index 0000000..5d7164b --- /dev/null +++ b/schemars/src/json_schema_impls/wrapper.rs @@ -0,0 +1,43 @@ +use crate::gen::SchemaGenerator; +use crate::schema::Schema; +use crate::JsonSchema; + +macro_rules! deref_impl { + ($($desc:tt)+) => { + impl $($desc)+ + where + T: JsonSchema, + { + fn is_referenceable() -> bool { + T::is_referenceable() + } + + fn schema_name() -> String { + T::schema_name() + } + + fn json_schema(gen: &mut SchemaGenerator) -> Schema { + T::json_schema(gen) + } + + fn json_schema_optional(gen: &mut SchemaGenerator) -> Schema { + T::json_schema_optional(gen) + } + } + }; +} + +deref_impl!(<'a, T: ?Sized> JsonSchema for &'a T); +deref_impl!(<'a, T: ?Sized> JsonSchema for &'a mut T); +deref_impl!( JsonSchema for Box); +deref_impl!( JsonSchema for std::rc::Rc); +deref_impl!( JsonSchema for std::rc::Weak); +deref_impl!( JsonSchema for std::sync::Arc); +deref_impl!( JsonSchema for std::sync::Weak); +deref_impl!( JsonSchema for std::sync::Mutex); +deref_impl!( JsonSchema for std::sync::RwLock); +deref_impl!( JsonSchema for std::cell::Cell); +deref_impl!( JsonSchema for std::cell::RefCell); +deref_impl!(<'a, T: ?Sized + ToOwned> JsonSchema for std::borrow::Cow<'a, T>); +deref_impl!( JsonSchema for std::num::Wrapping); +deref_impl!( JsonSchema for std::cmp::Reverse);