Skip to content

Commit

Permalink
Make Functions Send + Sync (#55)
Browse files Browse the repository at this point in the history
* Make Functions Send + Sync

* Fix formatting issue
  • Loading branch information
lucperkins authored Jun 26, 2024
1 parent 2f8a34c commit 5ecee90
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion interpreter/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'a> Context<'a> {

pub fn add_function<T: 'static, F>(&mut self, name: &str, value: F)
where
F: Handler<T> + 'static,
F: Handler<T> + 'static + Send + Sync,
{
if let Context::Root { functions, .. } = self {
functions.add(name, value);
Expand Down
10 changes: 5 additions & 5 deletions interpreter/src/magic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ pub struct FunctionRegistry {
impl FunctionRegistry {
pub(crate) fn add<H, T>(&mut self, name: &str, handler: H)
where
H: Handler<T> + 'static,
H: Handler<T> + 'static + Send + Sync,
T: 'static,
{
self.functions.insert(
Expand All @@ -323,18 +323,18 @@ impl FunctionRegistry {
}
}

pub trait Function {
pub trait Function: Send + Sync {
fn clone_box(&self) -> Box<dyn Function>;
fn into_callable<'a>(self: Box<Self>, ctx: &'a mut FunctionContext) -> Box<dyn Callable + 'a>;
fn call_with_context(self: Box<Self>, ctx: &mut FunctionContext) -> ResolveResult;
}

pub struct HandlerFunction<H: Clone> {
pub struct HandlerFunction<H: Clone + Send + Sync> {
pub handler: H,
pub into_callable: for<'a> fn(H, &'a mut FunctionContext) -> Box<dyn Callable + 'a>,
}

impl<H: Clone> Clone for HandlerFunction<H> {
impl<H: Clone + Send + Sync> Clone for HandlerFunction<H> {
fn clone(&self) -> Self {
Self {
handler: self.handler.clone(),
Expand All @@ -345,7 +345,7 @@ impl<H: Clone> Clone for HandlerFunction<H> {

impl<H> Function for HandlerFunction<H>
where
H: Clone + 'static,
H: Clone + Send + Sync + 'static,
{
fn clone_box(&self) -> Box<dyn Function> {
Box::new(self.clone())
Expand Down

0 comments on commit 5ecee90

Please sign in to comment.