Skip to content

Commit

Permalink
cow to &str
Browse files Browse the repository at this point in the history
  • Loading branch information
ssddOnTop committed May 23, 2024
1 parent 2f7168b commit 5c7af2b
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 16 deletions.
3 changes: 1 addition & 2 deletions src/cli/javascript/request_filter.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::sync::Arc;

use hyper::body::Bytes;
Expand Down Expand Up @@ -53,7 +52,7 @@ impl RequestFilter {
async fn on_request(&self, mut request: reqwest::Request) -> anyhow::Result<Response<Bytes>> {
let js_request = WorkerRequest::try_from(&request)?;
let event = Event::Request(js_request);
let command = self.worker.call(Cow::Borrowed("onRequest"), event).await?;
let command = self.worker.call("onRequest", event).await?;
match command {
Some(command) => match command {
Command::Request(js_request) => {
Expand Down
13 changes: 4 additions & 9 deletions src/cli/javascript/runtime.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use std::borrow::Cow;
use std::cell::{OnceCell, RefCell};
use std::fmt::{Debug, Formatter};
use std::thread;
Expand Down Expand Up @@ -83,13 +82,9 @@ impl Drop for Runtime {

#[async_trait::async_trait]
impl WorkerIO<Event, Command> for Runtime {
async fn call(
&self,
name: Cow<'async_trait, str>,
event: Event,
) -> anyhow::Result<Option<Command>> {
async fn call(&self, name: &'async_trait str, event: Event) -> anyhow::Result<Option<Command>> {
let script = self.script.clone();
let name = name.as_ref().to_string(); // TODO
let name = name.to_string(); // TODO
if let Some(runtime) = &self.tokio_runtime {
runtime
.spawn(async move {
Expand All @@ -107,11 +102,11 @@ impl WorkerIO<Event, Command> for Runtime {
impl WorkerIO<ConstValue, ConstValue> for Runtime {
async fn call(
&self,
name: Cow<'async_trait, str>,
name: &'async_trait str,
input: ConstValue,
) -> anyhow::Result<Option<ConstValue>> {
let script = self.script.clone();
let name = name.as_ref().to_string();
let name = name.to_string();
if let Some(runtime) = &self.tokio_runtime {
runtime
.spawn(async move {
Expand Down
3 changes: 1 addition & 2 deletions src/core/lambda/io.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use core::future::Future;
use std::borrow::Cow;
use std::hash::{Hash, Hasher};
use std::pin::Pin;
use std::sync::Arc;
Expand Down Expand Up @@ -144,7 +143,7 @@ impl IO {
.request_ctx
.runtime
.worker
.call(Cow::Borrowed(method), value)
.call(method, value)
.await
.map_err(EvaluationError::from)?;

Check warning on line 148 in src/core/lambda/io.rs

View check run for this annotation

Codecov / codecov/patch

src/core/lambda/io.rs#L140-L148

Added lines #L140 - L148 were not covered by tests

Expand Down
2 changes: 1 addition & 1 deletion src/core/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ pub type EntityCache = dyn Cache<Key = u64, Value = ConstValue>;
#[async_trait::async_trait]
pub trait WorkerIO<In, Out>: Send + Sync + 'static {
/// Calls a global JS function
async fn call(&self, name: Cow<'async_trait, str>, input: In) -> anyhow::Result<Option<Out>>;
async fn call(&self, name: &'async_trait str, input: In) -> anyhow::Result<Option<Out>>;
}

pub fn is_default<T: Default + Eq>(val: &T) -> bool {
Expand Down
3 changes: 1 addition & 2 deletions src/core/worker.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::borrow::Cow;

Check warning on line 1 in src/core/worker.rs

View workflow job for this annotation

GitHub Actions / Run Formatter and Lint Check

Diff in /home/runner/work/tailcall/tailcall/src/core/worker.rs
use crate::core::{Response, WorkerIO};

pub struct DefaultJsRuntime;

#[async_trait::async_trait]
impl<A: Send + Sync + 'static, B> WorkerIO<A, B> for DefaultJsRuntime {
async fn call(&self, _: Cow<'async_trait, str>, _: A) -> anyhow::Result<Option<B>> {
async fn call(&self, _: &'async_trait str, _: A) -> anyhow::Result<Option<B>> {
anyhow::bail!("JavaScript runtime is not supported in this build")
}

Check warning on line 10 in src/core/worker.rs

View check run for this annotation

Codecov / codecov/patch

src/core/worker.rs#L8-L10

Added lines #L8 - L10 were not covered by tests
}
Expand Down

0 comments on commit 5c7af2b

Please sign in to comment.