From 4d2b9cd37af2b9d6a145a04fc93117922e43df3a Mon Sep 17 00:00:00 2001 From: Ryan Dahl Date: Sat, 18 Apr 2020 20:05:13 -0400 Subject: Fix Op definitions (#4814) --- core/ops.rs | 32 ++++++++++---------------------- 1 file changed, 10 insertions(+), 22 deletions(-) (limited to 'core/ops.rs') diff --git a/core/ops.rs b/core/ops.rs index 16807196e..ab183f4de 100644 --- a/core/ops.rs +++ b/core/ops.rs @@ -10,30 +10,18 @@ pub type OpId = u32; pub type Buf = Box<[u8]>; -pub type OpAsyncFuture = Pin>>>; +pub type OpAsyncFuture = Pin>>; -pub(crate) type PendingOpFuture = - Pin>>>; - -pub type OpResult = Result, E>; - -// TODO(ry) Op::Async should be Op::Async(Pin>>) -// The error should be encoded in the Buf. Notice how Sync ops do not return a -// result. The Sync and Async should be symmetrical! -pub enum Op { +pub enum Op { Sync(Buf), - Async(OpAsyncFuture), + Async(OpAsyncFuture), /// AsyncUnref is the variation of Async, which doesn't block the program /// exiting. - AsyncUnref(OpAsyncFuture), + AsyncUnref(OpAsyncFuture), } -pub type CoreError = (); - -pub type CoreOp = Op; - /// Main type describing op -pub type OpDispatcher = dyn Fn(&[u8], Option) -> CoreOp + 'static; +pub type OpDispatcher = dyn Fn(&[u8], Option) -> Op + 'static; #[derive(Default)] pub struct OpRegistry { @@ -54,7 +42,7 @@ impl OpRegistry { pub fn register(&self, name: &str, op: F) -> OpId where - F: Fn(&[u8], Option) -> CoreOp + 'static, + F: Fn(&[u8], Option) -> Op + 'static, { let mut lock = self.dispatchers.write().unwrap(); let op_id = lock.len() as u32; @@ -83,7 +71,7 @@ impl OpRegistry { op_id: OpId, control: &[u8], zero_copy_buf: Option, - ) -> Option { + ) -> Option { // Op with id 0 has special meaning - it's a special op that is always // provided to retrieve op id map. The map consists of name to `OpId` // mappings. @@ -113,7 +101,7 @@ fn test_op_registry() { let test_id = op_registry.register("test", move |_, _| { c_.fetch_add(1, atomic::Ordering::SeqCst); - CoreOp::Sync(Box::new([])) + Op::Sync(Box::new([])) }); assert!(test_id != 0); @@ -149,9 +137,9 @@ fn register_op_during_call() { let c__ = c_.clone(); op_registry_.register("test", move |_, _| { c__.fetch_add(1, atomic::Ordering::SeqCst); - CoreOp::Sync(Box::new([])) + Op::Sync(Box::new([])) }); - CoreOp::Sync(Box::new([])) + Op::Sync(Box::new([])) }); assert!(test_id != 0); -- cgit v1.2.3