summaryrefslogtreecommitdiff
path: root/cli/ops/dispatch_json.rs
diff options
context:
space:
mode:
authorRyan Dahl <ry@tinyclouds.org>2020-08-12 10:44:58 -0400
committerGitHub <noreply@github.com>2020-08-12 16:44:58 +0200
commitf5a4f1fdc04b24cdfbef83842b9c42b5032c4059 (patch)
treef0ead2884b3b69b287a05a82885e30a541116063 /cli/ops/dispatch_json.rs
parent6706eb551532ee6c84ad013377ac2cd91681424a (diff)
Undo JsonOpDispatcher and OpDispatcher traits (#7023)
This reverts commit f83d672ffad7afb1473bd4f9b9c645539064c620. This reverts commit d51972377c1325076704d9faec2eee6f0e024496.
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 {