diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2021-04-02 15:47:57 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-02 09:47:57 -0400 |
commit | 058579da562989ed15c86598053644bbc86c6747 (patch) | |
tree | 7f0f2bf30684dcbb350b93d987771f17a4abd250 /core/ops_json.rs | |
parent | adf57610904cb4f4ef25fb077f6e39c9017a4ea9 (diff) |
refactor(ops): remove variadic buffers (#9944)
Diffstat (limited to 'core/ops_json.rs')
-rw-r--r-- | core/ops_json.rs | 26 |
1 files changed, 6 insertions, 20 deletions
diff --git a/core/ops_json.rs b/core/ops_json.rs index ee336830b..21c6b219f 100644 --- a/core/ops_json.rs +++ b/core/ops_json.rs @@ -2,7 +2,6 @@ use crate::error::AnyError; use crate::serialize_op_result; -use crate::BufVec; use crate::Op; use crate::OpFn; use crate::OpPayload; @@ -39,21 +38,14 @@ use std::rc::Rc; /// A more complete example is available in the examples directory. pub fn json_op_sync<F, V, R>(op_fn: F) -> Box<OpFn> where - F: Fn(&mut OpState, V, &mut [ZeroCopyBuf]) -> Result<R, AnyError> + 'static, + F: Fn(&mut OpState, V, Option<ZeroCopyBuf>) -> Result<R, AnyError> + 'static, V: DeserializeOwned, R: Serialize + 'static, { - Box::new(move |state, payload, buf: Option<ZeroCopyBuf>| -> Op { - // For sig compat map Option<ZeroCopyBuf> to BufVec - let mut bufs: BufVec = match buf { - Some(b) => vec![b], - None => vec![], - } - .into(); - + Box::new(move |state, payload, buf| -> Op { let result = payload .deserialize() - .and_then(|args| op_fn(&mut state.borrow_mut(), args, &mut bufs)); + .and_then(|args| op_fn(&mut state.borrow_mut(), args, buf)); Op::Sync(serialize_op_result(result, state)) }) } @@ -84,26 +76,20 @@ where /// A more complete example is available in the examples directory. pub fn json_op_async<F, V, R, RV>(op_fn: F) -> Box<OpFn> where - F: Fn(Rc<RefCell<OpState>>, V, BufVec) -> R + 'static, + F: Fn(Rc<RefCell<OpState>>, V, Option<ZeroCopyBuf>) -> R + 'static, V: DeserializeOwned, R: Future<Output = Result<RV, AnyError>> + 'static, RV: Serialize + 'static, { let try_dispatch_op = move |state: Rc<RefCell<OpState>>, p: OpPayload, - b: Option<ZeroCopyBuf>| + buf: Option<ZeroCopyBuf>| -> Result<Op, AnyError> { - // For sig compat map Option<ZeroCopyBuf> to BufVec - let bufs: BufVec = match b { - Some(b) => vec![b], - None => vec![], - } - .into(); // Parse args let args = p.deserialize()?; use crate::futures::FutureExt; - let fut = op_fn(state.clone(), args, bufs) + let fut = op_fn(state.clone(), args, buf) .map(move |result| serialize_op_result(result, state)); Ok(Op::Async(Box::pin(fut))) }; |