Implement JsonSchema for Weak/Wrapping/Reverse

This commit is contained in:
Graham Esau 2019-10-27 19:02:38 +00:00
parent e11d5e5a98
commit e6c178117c
3 changed files with 44 additions and 40 deletions

View file

@ -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!(<T> JsonSchema for Box<T>);
deref_impl!(<T> JsonSchema for std::rc::Rc<T>);
deref_impl!(<T> JsonSchema for std::sync::Arc<T>);
deref_impl!(<T> JsonSchema for std::sync::Mutex<T>);
deref_impl!(<T> JsonSchema for std::sync::RwLock<T>);
deref_impl!(<T> JsonSchema for std::cell::Cell<T>);
deref_impl!(<T> JsonSchema for std::cell::RefCell<T>);
deref_impl!(<'a, T: ToOwned> JsonSchema for std::borrow::Cow<'a, T>);

View file

@ -10,7 +10,7 @@ mod array;
#[cfg(feature = "chrono")] #[cfg(feature = "chrono")]
mod chrono; mod chrono;
mod core; mod core;
mod deref; mod wrapper;
mod maps; mod maps;
mod primitives; mod primitives;
mod sequences; mod sequences;

View file

@ -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!(<T: ?Sized> JsonSchema for Box<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::rc::Rc<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::rc::Weak<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::sync::Arc<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::sync::Weak<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::sync::Mutex<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::sync::RwLock<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::cell::Cell<T>);
deref_impl!(<T: ?Sized> JsonSchema for std::cell::RefCell<T>);
deref_impl!(<'a, T: ?Sized + ToOwned> JsonSchema for std::borrow::Cow<'a, T>);
deref_impl!(<T> JsonSchema for std::num::Wrapping<T>);
deref_impl!(<T> JsonSchema for std::cmp::Reverse<T>);