Skip to content

Commit

Permalink
Add Send requirement to GenTransform
Browse files Browse the repository at this point in the history
This means `SchemaSettings` and `SchemaGenerator` are both now `Send`
  • Loading branch information
GREsau committed Aug 8, 2024
1 parent 324be32 commit ac12438
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions schemars/src/gen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ impl SchemaSettings {
}

/// Appends the given transform to the list of [transforms](SchemaSettings::transforms) for these `SchemaSettings`.
pub fn with_transform(mut self, transform: impl Transform + Clone + 'static) -> Self {
pub fn with_transform(mut self, transform: impl Transform + Clone + 'static + Send) -> Self {
self.transforms.push(Box::new(transform));
self
}
Expand Down Expand Up @@ -507,6 +507,7 @@ fn json_pointer_mut<'a>(
/// - [`Transform`]
/// - [`std::any::Any`] (implemented for all `'static` types)
/// - [`std::clone::Clone`]
/// - [`std::marker::Send`]
///
/// # Example
/// ```
Expand All @@ -525,7 +526,7 @@ fn json_pointer_mut<'a>(
/// let v: &dyn GenTransform = &MyTransform;
/// assert!(v.as_any().is::<MyTransform>());
/// ```
pub trait GenTransform: Transform + DynClone + Any {
pub trait GenTransform: Transform + DynClone + Any + Send {
/// Upcasts this transform into an [`Any`], which can be used to inspect and manipulate it as its concrete type.
fn as_any(&self) -> &dyn Any;
}
Expand All @@ -534,7 +535,7 @@ dyn_clone::clone_trait_object!(GenTransform);

impl<T> GenTransform for T
where
T: Transform + Clone + Any,
T: Transform + Clone + Any + Send,
{
fn as_any(&self) -> &dyn Any {
self
Expand All @@ -546,3 +547,11 @@ impl Debug for Box<dyn GenTransform> {
self._debug_type_name(f)
}
}

#[allow(dead_code)]
fn assert_properties() {
fn is_send<T: Send>() {}

is_send::<SchemaSettings>();
is_send::<SchemaGenerator>();
}

0 comments on commit ac12438

Please sign in to comment.