Skip to content

Commit

Permalink
feat!: require send as well as sync
Browse files Browse the repository at this point in the history
When the lazy_static feature "spin_no_std" is enabled, the bounds of Send is required
This may happen if another dependency adds that feature, then cargo unifies the two dependency trees erroneously, causing a compile error
requiring Send on Runtime.

This is technically a breaking change in case anyone had a Sync but not Send type implementing Function

See more: rust-lang-nursery/lazy-static.rs#204
  • Loading branch information
ctrlaltf24 committed Dec 12, 2023
1 parent 41e6566 commit 66464f0
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions jmespath/src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use crate::{Context, ErrorReason, JmespathError, Rcvar, RuntimeError};
use serde_json::Number;

/// Represents a JMESPath function.
pub trait Function: Sync {
pub trait Function: Sync + Send {
/// Evaluates the function against an in-memory variable.
fn evaluate(&self, args: &[Rcvar], ctx: &mut Context<'_>) -> SearchResult;
}
Expand Down Expand Up @@ -102,14 +102,14 @@ pub struct CustomFunction {
/// Signature used to validate the function.
signature: Signature,
/// Function to invoke after validating the signature.
f: Box<dyn Fn(&[Rcvar], &mut Context<'_>) -> SearchResult + Sync>,
f: Box<dyn Fn(&[Rcvar], &mut Context<'_>) -> SearchResult + Sync + Send>,
}

impl CustomFunction {
/// Creates a new custom function.
pub fn new(
fn_signature: Signature,
f: Box<dyn Fn(&[Rcvar], &mut Context<'_>) -> SearchResult + Sync>,
f: Box<dyn Fn(&[Rcvar], &mut Context<'_>) -> SearchResult + Sync + Send>,
) -> CustomFunction {
CustomFunction {
signature: fn_signature,
Expand All @@ -132,7 +132,7 @@ impl Function for CustomFunction {
/// validation, it is recommended to use CustomFunction.
impl<F> Function for F
where
F: Sync + Fn(&[Rcvar], &mut Context<'_>) -> SearchResult,
F: Send + Sync + Fn(&[Rcvar], &mut Context<'_>) -> SearchResult,
{
fn evaluate(&self, args: &[Rcvar], ctx: &mut Context<'_>) -> SearchResult {
(self)(args, ctx)
Expand Down

0 comments on commit 66464f0

Please sign in to comment.