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:
Transform
std::any::Any
(implemented for all'static
types)std::clone::Clone
std::marker::Send
§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
impl dyn GenTransform
Sourcepub fn is<T: Transform + Clone + Any + Send>(&self) -> bool
pub fn is<T: Transform + Clone + Any + Send>(&self) -> bool
Returns true
if the inner transform is of type T
.
Sourcepub fn downcast_ref<T: Transform + Clone + Any + Send>(&self) -> Option<&T>
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);
Sourcepub fn downcast_mut<T: Transform + Clone + Any + Send>(
&mut self,
) -> Option<&mut T>
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;
}
}