Add Send requirement to GenTransform

This means `SchemaSettings` and `SchemaGenerator` are both now `Send`
This commit is contained in:
Graham Esau 2024-08-08 22:04:39 +01:00
parent 324be32de6
commit a1c3bcd5cf

View file

@ -140,7 +140,7 @@ impl SchemaSettings {
} }
/// Appends the given transform to the list of [transforms](SchemaSettings::transforms) for these `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.transforms.push(Box::new(transform));
self self
} }
@ -507,6 +507,7 @@ fn json_pointer_mut<'a>(
/// - [`Transform`] /// - [`Transform`]
/// - [`std::any::Any`] (implemented for all `'static` types) /// - [`std::any::Any`] (implemented for all `'static` types)
/// - [`std::clone::Clone`] /// - [`std::clone::Clone`]
/// - [`std::marker::Send`]
/// ///
/// # Example /// # Example
/// ``` /// ```
@ -525,7 +526,7 @@ fn json_pointer_mut<'a>(
/// let v: &dyn GenTransform = &MyTransform; /// let v: &dyn GenTransform = &MyTransform;
/// assert!(v.as_any().is::<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. /// 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; fn as_any(&self) -> &dyn Any;
} }
@ -534,7 +535,7 @@ dyn_clone::clone_trait_object!(GenTransform);
impl<T> GenTransform for T impl<T> GenTransform for T
where where
T: Transform + Clone + Any, T: Transform + Clone + Any + Send,
{ {
fn as_any(&self) -> &dyn Any { fn as_any(&self) -> &dyn Any {
self self
@ -546,3 +547,10 @@ impl Debug for Box<dyn GenTransform> {
self._debug_type_name(f) self._debug_type_name(f)
} }
} }
fn _assert_send() {
fn _assert<T: Send>() {}
_assert::<SchemaSettings>();
_assert::<SchemaGenerator>();
}