From b6733c98caee437365e1e222da42054fe81415b7 Mon Sep 17 00:00:00 2001 From: lukasmittag Date: Wed, 17 Apr 2024 18:12:59 +0200 Subject: [PATCH] Remove optional --- databroker/src/broker.rs | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/databroker/src/broker.rs b/databroker/src/broker.rs index 6a48052b..77df1a2e 100644 --- a/databroker/src/broker.rs +++ b/databroker/src/broker.rs @@ -155,7 +155,7 @@ pub struct QuerySubscription { pub struct ChangeSubscription { entries: HashMap>, - sender: Option>, + sender: mpsc::Sender, permissions: Permissions, } @@ -661,8 +661,7 @@ impl Subscriptions { } }); self.change_subscriptions.retain_mut(|sub| { - if let Some(sender) = &sub.sender { - if sender.is_closed() { + if sub.sender.is_closed() { info!("Subscriber gone: removing subscription"); false } else { @@ -675,10 +674,6 @@ impl Subscriptions { Err(err) => panic!("Error: {:?}", err), } } - } else { - info!("Subscriber gone: removing subscription"); - false - } }); } } @@ -749,13 +744,12 @@ impl ChangeSubscription { }; if notifications.updates.is_empty() { Ok(()) - } else if let Some(sender) = &self.sender { - match sender.send(notifications).await { + } + else { + match &self.sender.send(notifications).await { Ok(()) => Ok(()), Err(_) => Err(NotificationError {}), } - } else { - Err(NotificationError {}) } } else { Ok(()) @@ -792,13 +786,10 @@ impl ChangeSubscription { } notifications }; - if let Some(sender) = &self.sender { - match sender.send(notifications).await { - Ok(()) => Ok(()), - Err(_) => Err(NotificationError {}), - } - } else { - Err(NotificationError {}) + match &self.sender.send(notifications).await + { + Ok(()) => Ok(()), + Err(_) => Err(NotificationError {}), } } } @@ -1478,7 +1469,7 @@ impl<'a, 'b> AuthorizedAccess<'a, 'b> { let (sender, receiver) = mpsc::channel(10); let subscription = ChangeSubscription { entries: valid_entries, - sender: Some(sender), + sender: sender, permissions: self.permissions.clone(), };