From 501593af23e2ad0d55b7fabb0e5a0b63786361b4 Mon Sep 17 00:00:00 2001 From: Niko Date: Wed, 3 May 2023 21:20:32 +0300 Subject: [PATCH] impl of SoS single or stream --- p2p-net/src/actor.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/p2p-net/src/actor.rs b/p2p-net/src/actor.rs index a604a3d..3100eb0 100644 --- a/p2p-net/src/actor.rs +++ b/p2p-net/src/actor.rs @@ -82,7 +82,36 @@ pub struct Actor< pub enum SoS { Single(B), - Stream(mpsc::UnboundedReceiver), + Stream(Receiver), +} + +impl SoS { + pub fn is_single(&self) -> bool { + if let Self::Single(b) = self { + true + } else { + false + } + } + pub fn is_stream(&self) -> bool { + !self.is_single() + } + pub fn unwrap_single(self) -> B { + match self { + Self::Single(s) => s, + Self::Stream(s) => { + panic!("called `unwrap_single()` on a `Stream` value") + } + } + } + pub fn unwrap_stream(self) -> Receiver { + match self { + Self::Stream(s) => s, + Self::Single(s) => { + panic!("called `unwrap_stream()` on a `Single` value") + } + } + } } impl<