summaryrefslogtreecommitdiff
path: root/cli/ops/dispatch_json.rs
diff options
context:
space:
mode:
Diffstat (limited to 'cli/ops/dispatch_json.rs')
-rw-r--r--cli/ops/dispatch_json.rs31
1 files changed, 5 insertions, 26 deletions
diff --git a/cli/ops/dispatch_json.rs b/cli/ops/dispatch_json.rs
index ad6947dd1..2ec9d6c2f 100644
--- a/cli/ops/dispatch_json.rs
+++ b/cli/ops/dispatch_json.rs
@@ -3,7 +3,6 @@ use crate::op_error::OpError;
use deno_core::Buf;
use deno_core::CoreIsolateState;
use deno_core::Op;
-use deno_core::OpDispatcher;
use deno_core::ZeroCopyBuf;
use futures::future::FutureExt;
pub use serde_derive::Deserialize;
@@ -45,36 +44,16 @@ struct AsyncArgs {
promise_id: Option<u64>,
}
-/// Like OpDispatcher but with additional json `Value` parameter
-/// and return a result of `JsonOp` instead of `Op`.
-pub trait JsonOpDispatcher {
- fn dispatch(
- &self,
- isolate_state: &mut CoreIsolateState,
- json: Value,
- zero_copy: &mut [ZeroCopyBuf],
- ) -> Result<JsonOp, OpError>;
-}
-
-impl<F> JsonOpDispatcher for F
+pub fn json_op<D>(
+ d: D,
+) -> impl Fn(&mut CoreIsolateState, &mut [ZeroCopyBuf]) -> Op
where
- F: Fn(
+ D: Fn(
&mut CoreIsolateState,
Value,
&mut [ZeroCopyBuf],
) -> Result<JsonOp, OpError>,
{
- fn dispatch(
- &self,
- isolate_state: &mut CoreIsolateState,
- json: Value,
- zero_copy: &mut [ZeroCopyBuf],
- ) -> Result<JsonOp, OpError> {
- self(isolate_state, json, zero_copy)
- }
-}
-
-pub fn json_op(d: impl JsonOpDispatcher) -> impl OpDispatcher {
move |isolate_state: &mut CoreIsolateState, zero_copy: &mut [ZeroCopyBuf]| {
assert!(!zero_copy.is_empty(), "Expected JSON string at position 0");
let async_args: AsyncArgs = match serde_json::from_slice(&zero_copy[0]) {
@@ -89,7 +68,7 @@ pub fn json_op(d: impl JsonOpDispatcher) -> impl OpDispatcher {
let result = serde_json::from_slice(&zero_copy[0])
.map_err(OpError::from)
- .and_then(|args| d.dispatch(isolate_state, args, &mut zero_copy[1..]));
+ .and_then(|args| d(isolate_state, args, &mut zero_copy[1..]));
// Convert to Op
match result {