From 40a2bf5057e6f54a653b77f639fd44a18c244835 Mon Sep 17 00:00:00 2001 From: Sandipsinh Rathod Date: Fri, 24 May 2024 19:40:49 +0530 Subject: [PATCH] change sig from `&In` to `In` --- src/cli/javascript/request_filter.rs | 2 +- src/cli/javascript/runtime.rs | 11 +++-------- src/core/lambda/io.rs | 2 +- src/core/mod.rs | 6 +----- src/core/worker.rs | 10 ++-------- 5 files changed, 8 insertions(+), 23 deletions(-) diff --git a/src/cli/javascript/request_filter.rs b/src/cli/javascript/request_filter.rs index 52a7a6d808..c40defca40 100644 --- a/src/cli/javascript/request_filter.rs +++ b/src/cli/javascript/request_filter.rs @@ -52,7 +52,7 @@ impl RequestFilter { async fn on_request(&self, mut request: reqwest::Request) -> anyhow::Result> { let js_request = WorkerRequest::try_from(&request)?; let event = Event::Request(js_request); - let command = self.worker.call("onRequest", &event).await?; + let command = self.worker.call("onRequest", event).await?; match command { Some(command) => match command { Command::Request(js_request) => { diff --git a/src/cli/javascript/runtime.rs b/src/cli/javascript/runtime.rs index 893d92eab4..18c1f10cd9 100644 --- a/src/cli/javascript/runtime.rs +++ b/src/cli/javascript/runtime.rs @@ -82,14 +82,9 @@ impl Drop for Runtime { #[async_trait::async_trait] impl WorkerIO for Runtime { - async fn call( - &self, - name: &'async_trait str, - event: &'async_trait Event, - ) -> anyhow::Result> { + async fn call(&self, name: &'async_trait str, event: Event) -> anyhow::Result> { let script = self.script.clone(); let name = name.to_string(); // TODO - let event = event.clone(); // TODO if let Some(runtime) = &self.tokio_runtime { runtime .spawn(async move { @@ -108,11 +103,11 @@ impl WorkerIO for Runtime { async fn call( &self, name: &'async_trait str, - input: &'async_trait ConstValue, + input: ConstValue, ) -> anyhow::Result> { let script = self.script.clone(); let name = name.to_string(); - let value = serde_json::to_string(input)?; + let value = serde_json::to_string(&input)?; if let Some(runtime) = &self.tokio_runtime { runtime .spawn(async move { diff --git a/src/core/lambda/io.rs b/src/core/lambda/io.rs index 683bce296d..38d4532b3a 100644 --- a/src/core/lambda/io.rs +++ b/src/core/lambda/io.rs @@ -141,7 +141,7 @@ impl IO { Ok(res.body) } IO::Js { name: method } => { - let value = ctx.value().unwrap_or(&ConstValue::Null); + let value = ctx.value().cloned().unwrap_or(ConstValue::Null); let value = ctx .request_ctx .runtime diff --git a/src/core/mod.rs b/src/core/mod.rs index 8acd8e719b..c4d32bb90e 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -84,11 +84,7 @@ pub type EntityCache = dyn Cache; #[async_trait::async_trait] pub trait WorkerIO: Send + Sync + 'static { /// Calls a global JS function - async fn call( - &self, - name: &'async_trait str, - input: &'async_trait In, - ) -> anyhow::Result>; + async fn call(&self, name: &'async_trait str, input: In) -> anyhow::Result>; } pub fn is_default(val: &T) -> bool { diff --git a/src/core/worker.rs b/src/core/worker.rs index 388f0a4a82..fa314bbd80 100644 --- a/src/core/worker.rs +++ b/src/core/worker.rs @@ -4,7 +4,7 @@ pub struct DefaultJsRuntime; #[async_trait::async_trait] impl WorkerIO for DefaultJsRuntime { - async fn call(&self, _: &'async_trait str, _: &'async_trait A) -> anyhow::Result> { + async fn call(&self, _: &'async_trait str, _: A) -> anyhow::Result> { anyhow::bail!("JavaScript runtime is not supported in this build") } } @@ -15,13 +15,7 @@ pub struct WorkerResponse(pub Response); #[derive(Debug)] pub struct WorkerRequest(pub reqwest::Request); -impl Clone for WorkerRequest { - fn clone(&self) -> Self { - WorkerRequest(self.0.try_clone().unwrap()) - } -} - -#[derive(Debug, Clone)] +#[derive(Debug)] pub enum Event { Request(WorkerRequest), }