diff options
author | Inteon <42113979+inteon@users.noreply.github.com> | 2021-03-20 17:51:08 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-20 17:51:08 +0100 |
commit | 1251c893212d57303ecdfa8d953d1e487cb7ec7d (patch) | |
tree | 80b3a55872db0a4ee0c9e594601d330e39ca4873 /runtime/ops/mod.rs | |
parent | 0d26a82ea9169c013e9b0f29c1ec418b28e273cf (diff) |
refactor: Move bin ops to deno_core and unify logic with json ops (#9457)
This commit moves implementation of bin ops to "deno_core" crates
as well as unifying logic between bin ops and json ops to reuse
as much code as possible (both in Rust and JavaScript).
Diffstat (limited to 'runtime/ops/mod.rs')
-rw-r--r-- | runtime/ops/mod.rs | 20 |
1 files changed, 8 insertions, 12 deletions
diff --git a/runtime/ops/mod.rs b/runtime/ops/mod.rs index e082c5d3a..2e94d99f5 100644 --- a/runtime/ops/mod.rs +++ b/runtime/ops/mod.rs @@ -8,7 +8,6 @@ pub mod io; pub mod net; #[cfg(unix)] mod net_unix; -mod ops_buffer; pub mod os; pub mod permissions; pub mod plugin; @@ -25,6 +24,8 @@ pub mod websocket; pub mod worker_host; use crate::metrics::metrics_op; +use deno_core::bin_op_async; +use deno_core::bin_op_sync; use deno_core::error::AnyError; use deno_core::json_op_async; use deno_core::json_op_sync; @@ -33,10 +34,8 @@ use deno_core::serde::Serialize; use deno_core::BufVec; use deno_core::JsRuntime; use deno_core::OpState; +use deno_core::ValueOrVector; use deno_core::ZeroCopyBuf; -use ops_buffer::buffer_op_async; -use ops_buffer::buffer_op_sync; -use ops_buffer::ValueOrVector; use std::cell::RefCell; use std::future::Future; use std::rc::Rc; @@ -63,24 +62,21 @@ where rt.register_op(name, metrics_op(name, json_op_sync(op_fn))); } -pub fn reg_buffer_async<F, R, RV>( - rt: &mut JsRuntime, - name: &'static str, - op_fn: F, -) where +pub fn reg_bin_async<F, R, RV>(rt: &mut JsRuntime, name: &'static str, op_fn: F) +where F: Fn(Rc<RefCell<OpState>>, u32, BufVec) -> R + 'static, R: Future<Output = Result<RV, AnyError>> + 'static, RV: ValueOrVector, { - rt.register_op(name, metrics_op(name, buffer_op_async(op_fn))); + rt.register_op(name, metrics_op(name, bin_op_async(op_fn))); } -pub fn reg_buffer_sync<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) +pub fn reg_bin_sync<F, R>(rt: &mut JsRuntime, name: &'static str, op_fn: F) where F: Fn(&mut OpState, u32, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static, R: ValueOrVector, { - rt.register_op(name, metrics_op(name, buffer_op_sync(op_fn))); + rt.register_op(name, metrics_op(name, bin_op_sync(op_fn))); } /// `UnstableChecker` is a struct so it can be placed inside `GothamState`; |