Trait GenTransform

Source
pub trait GenTransform:
    Transform
    + DynClone
    + Any
    + Send { }
Expand description

A Transform which implements additional traits required to be included in a SchemaSettings.

You will rarely need to use this trait directly as it is automatically implemented for any type which implements all of:

§Example

use schemars::transform::Transform;
use schemars::generate::GenTransform;

#[derive(Debug, Clone)]
struct MyTransform;

impl Transform for MyTransform {
  fn transform(&mut self, schema: &mut schemars::Schema) {
    todo!()
  }
}

let v: &dyn GenTransform = &MyTransform;
assert!(v.is::<MyTransform>());

Implementations§

Source§

impl dyn GenTransform

Source

pub fn is<T: Transform + Clone + Any + Send>(&self) -> bool

Returns true if the inner transform is of type T.

Source

pub fn downcast_ref<T: Transform + Clone + Any + Send>(&self) -> Option<&T>

Returns some reference to the inner transform if it is of type T, or None if it isn’t.

§Example

To remove a specific transform from an instance of SchemaSettings:

use schemars::generate::SchemaSettings;
use schemars::transform::ReplaceBoolSchemas;

let mut settings = SchemaSettings::openapi3();
let original_len = settings.transforms.len();

settings.transforms.retain(|t| !t.is::<ReplaceBoolSchemas>());

assert_eq!(settings.transforms.len(), original_len - 1);
Source

pub fn downcast_mut<T: Transform + Clone + Any + Send>( &mut self, ) -> Option<&mut T>

Returns some mutable reference to the inner transform if it is of type T, or None if it isn’t.

§Example

To modify a specific transform in an instance of SchemaSettings:

use schemars::generate::SchemaSettings;
use schemars::transform::ReplaceBoolSchemas;

let mut settings = SchemaSettings::openapi3();
for t in &mut settings.transforms {
    if let Some(replace_bool_schemas) = t.downcast_mut::<ReplaceBoolSchemas>() {
        replace_bool_schemas.skip_additional_properties = false;
    }
}
Source

pub fn downcast<T: Transform + Clone + Any + Send>( self: Box<Self>, ) -> Result<Box<T>, Box<Self>>

Attempts to downcast the box to a concrete type.

If the inner transform is not of type T, this returns self wrapped in an Err so that it can still be used.

Trait Implementations§

Source§

impl Debug for Box<dyn GenTransform>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Implementors§

Source§

impl<T> GenTransform for T
where T: Transform + Clone + Any + Send,