Simplify function types

This commit is contained in:
Joscha 2022-06-22 21:12:03 +02:00
parent c0fc9589dc
commit 956cb51231

View file

@ -67,14 +67,13 @@ pub struct Joining {
} }
impl Joining { impl Joining {
fn on_data(&mut self, data: Data) -> anyhow::Result<()> { fn on_data(&mut self, data: Data) {
match data { match data {
Data::BounceEvent(p) => self.bounce = Some(p), Data::BounceEvent(p) => self.bounce = Some(p),
Data::HelloEvent(p) => self.hello = Some(p), Data::HelloEvent(p) => self.hello = Some(p),
Data::SnapshotEvent(p) => self.snapshot = Some(p), Data::SnapshotEvent(p) => self.snapshot = Some(p),
_ => {} _ => {}
} }
Ok(())
} }
fn joined(&self) -> Option<Joined> { fn joined(&self) -> Option<Joined> {
@ -104,7 +103,7 @@ pub struct Joined {
} }
impl Joined { impl Joined {
fn on_data(&mut self, data: Data) -> anyhow::Result<()> { fn on_data(&mut self, data: Data) {
match data { match data {
Data::JoinEvent(p) => { Data::JoinEvent(p) => {
self.listing.insert(p.0.id.clone(), p.0); self.listing.insert(p.0.id.clone(), p.0);
@ -135,7 +134,6 @@ impl Joined {
// not even look at it. // not even look at it.
_ => {} _ => {}
} }
Ok(())
} }
} }
@ -170,7 +168,7 @@ impl State {
packet_tx: mpsc::UnboundedSender<Data>, packet_tx: mpsc::UnboundedSender<Data>,
) { ) {
let (ws_tx, mut ws_rx) = ws.split(); let (ws_tx, mut ws_rx) = ws.split();
let state = Self { let mut state = Self {
ws_tx, ws_tx,
last_id: 0, last_id: 0,
replies: Replies::new(Duration::from_secs(10)), // TODO Make configurable replies: Replies::new(Duration::from_secs(10)), // TODO Make configurable
@ -209,7 +207,7 @@ impl State {
} }
async fn handle_events( async fn handle_events(
mut self, &mut self,
event_tx: &mpsc::UnboundedSender<Event>, event_tx: &mpsc::UnboundedSender<Event>,
event_rx: &mut mpsc::UnboundedReceiver<Event>, event_rx: &mut mpsc::UnboundedReceiver<Event>,
) -> anyhow::Result<()> { ) -> anyhow::Result<()> {
@ -276,12 +274,12 @@ impl State {
if let Ok(data) = packet.content { if let Ok(data) = packet.content {
match &mut self.status { match &mut self.status {
Status::Joining(joining) => { Status::Joining(joining) => {
joining.on_data(data)?; joining.on_data(data);
if let Some(joined) = joining.joined() { if let Some(joined) = joining.joined() {
self.status = Status::Joined(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<C>(&self, cmd: C) -> Result<C::Reply, Error> pub async fn send<C>(&self, cmd: C) -> Result<C::Reply, Error>
where where
C: Command + Into<Data>, C: Command + Into<Data>,
C::Reply: TryFrom<Data, Error = ()>, C::Reply: TryFrom<Data>,
{ {
let (tx, rx) = oneshot::channel(); let (tx, rx) = oneshot::channel();
self.event_tx self.event_tx