From 956cb512314b22fd23fda67b15666bb01383cded Mon Sep 17 00:00:00 2001 From: Joscha Date: Wed, 22 Jun 2022 21:12:03 +0200 Subject: [PATCH] Simplify function types --- cove-tui/src/euph/conn.rs | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/cove-tui/src/euph/conn.rs b/cove-tui/src/euph/conn.rs index 5242f81..d4d0682 100644 --- a/cove-tui/src/euph/conn.rs +++ b/cove-tui/src/euph/conn.rs @@ -67,14 +67,13 @@ pub struct Joining { } impl Joining { - fn on_data(&mut self, data: Data) -> anyhow::Result<()> { + fn on_data(&mut self, data: Data) { match data { Data::BounceEvent(p) => self.bounce = Some(p), Data::HelloEvent(p) => self.hello = Some(p), Data::SnapshotEvent(p) => self.snapshot = Some(p), _ => {} } - Ok(()) } fn joined(&self) -> Option { @@ -104,7 +103,7 @@ pub struct Joined { } impl Joined { - fn on_data(&mut self, data: Data) -> anyhow::Result<()> { + fn on_data(&mut self, data: Data) { match data { Data::JoinEvent(p) => { self.listing.insert(p.0.id.clone(), p.0); @@ -135,7 +134,6 @@ impl Joined { // not even look at it. _ => {} } - Ok(()) } } @@ -170,7 +168,7 @@ impl State { packet_tx: mpsc::UnboundedSender, ) { let (ws_tx, mut ws_rx) = ws.split(); - let state = Self { + let mut state = Self { ws_tx, last_id: 0, replies: Replies::new(Duration::from_secs(10)), // TODO Make configurable @@ -209,7 +207,7 @@ impl State { } async fn handle_events( - mut self, + &mut self, event_tx: &mpsc::UnboundedSender, event_rx: &mut mpsc::UnboundedReceiver, ) -> anyhow::Result<()> { @@ -276,12 +274,12 @@ impl State { if let Ok(data) = packet.content { match &mut self.status { Status::Joining(joining) => { - joining.on_data(data)?; + joining.on_data(data); if let Some(joined) = joining.joined() { self.status = Status::Joined(joined); } } - Status::Joined(joined) => joined.on_data(data)?, + Status::Joined(joined) => joined.on_data(data), } } @@ -368,7 +366,7 @@ impl ConnTx { pub async fn send(&self, cmd: C) -> Result where C: Command + Into, - C::Reply: TryFrom, + C::Reply: TryFrom, { let (tx, rx) = oneshot::channel(); self.event_tx