From 310612b116d3e2c8bced08c3b7ee482c66011b57 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<