Skip to main content

SchemaSerialize

Trait SchemaSerialize 

Source
pub trait SchemaSerialize: ToSchema {
    // Required methods
    fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
       where S: Serializer;
    fn is_present(&self) -> bool;
}
Expand description

A type that is serializable according to its schema specification.

This trait is similar to serde’s Serialize, but allows

  • “automatic”, type-based optional properties, which prevents littering your codebase with #[serde(skip_serializing_if="...")]
  • deviating from the default or third-party serde implementations (e.g. for the time crate)

Required Methods§

Source

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes an object of this type.

Users of this trait should only call this method if is_present is true and implementations should return an error in this case.

Source

fn is_present(&self) -> bool

Determines whether a property of this type should be serialized within a JSON object.

If false is returned for a property value, it is not serialized (i.e. omitted from the JSON object). Therefore, if <Self as ToSchema>::REQUIRED == true, this method must never return false, otherwise the schema will be violated in these cases.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl SchemaSerialize for Value
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for bool
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for f32
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for f64
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for i8
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for i16
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for i32
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for i64
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for i128
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for str
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for u8
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for u16
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for u32
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for u64
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for u128
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for ()
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl SchemaSerialize for String
where Self: Serialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<'a, T> SchemaSerialize for Cow<'a, T>

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<'a, T> SchemaSerialize for &'a T
where T: SchemaSerialize + ?Sized,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<K, V> SchemaSerialize for BTreeMap<K, V>

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<K, V, H> SchemaSerialize for HashMap<K, V, H>

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for Option<T>
where T: SchemaSerialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for [T]
where Self: ToSchema, T: SchemaSerialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for Box<T>
where T: SchemaSerialize + ?Sized,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for LinkedList<T>
where Self: ToSchema, T: SchemaSerialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for Rc<T>
where T: SchemaSerialize + ?Sized,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for Arc<T>
where T: SchemaSerialize + ?Sized,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for Vec<T>
where Self: ToSchema, T: SchemaSerialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T> SchemaSerialize for RefCell<T>
where T: SchemaSerialize + ?Sized,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Source§

impl<T, H> SchemaSerialize for HashSet<T, H>
where Self: ToSchema, T: SchemaSerialize,

Source§

fn schema_serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Source§

fn is_present(&self) -> bool

Implementors§

Source§

impl<'i, I, M> SchemaSerialize for IteratorArray<'i, I, M>
where I: Iterator + 'i, M: IteratorItemMapper<I::Item>,

Source§

impl<I, K, V> SchemaSerialize for IteratorMap<I>

Source§

impl<T> SchemaSerialize for Nullable<T>
where T: SchemaSerialize,