Skip to main content

GenTransform

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>(&self) -> bool
where T: Transform + Clone + Any + Send,

Returns true if the inner transform is of type T.

Source

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

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>(&mut self) -> Option<&mut T>
where T: Transform + Clone + Any + Send,

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>( self: Box<dyn GenTransform>, ) -> Result<Box<T>, Box<dyn GenTransform>>
where T: Transform + Clone + Any + Send,

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<'clone> Clone for Box<dyn GenTransform + 'clone>

Source§

fn clone(&self) -> Box<dyn GenTransform + 'clone>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'clone> Clone for Box<dyn GenTransform + Send + 'clone>

Source§

fn clone(&self) -> Box<dyn GenTransform + Send + 'clone>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'clone> Clone for Box<dyn GenTransform + Sync + 'clone>

Source§

fn clone(&self) -> Box<dyn GenTransform + Sync + 'clone>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'clone> Clone for Box<dyn GenTransform + Sync + Send + 'clone>

Source§

fn clone(&self) -> Box<dyn GenTransform + Sync + Send + 'clone>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Box<dyn GenTransform>

Source§

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

Formats the value using the given formatter. Read more

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

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