Remove some_or_remove, ok_or_remove macros
This commit is contained in:
parent
325c5e6e5c
commit
e4e321c589
3 changed files with 16 additions and 40 deletions
|
|
@ -14,7 +14,7 @@ use log::{debug, error, info, warn};
|
|||
use tokio::select;
|
||||
use tokio::sync::oneshot;
|
||||
|
||||
use crate::macros::{logging_unwrap, ok_or_return};
|
||||
use crate::macros::logging_unwrap;
|
||||
use crate::vault::EuphRoomVault;
|
||||
|
||||
const LOG_INTERVAL: Duration = Duration::from_secs(10);
|
||||
|
|
@ -209,7 +209,7 @@ impl Room {
|
|||
|
||||
async fn on_packet(&mut self, packet: ParsedPacket) {
|
||||
let room_name = &self.instance.config().room;
|
||||
let data = ok_or_return!(&packet.content);
|
||||
let Ok(data) = &packet.content else { return; };
|
||||
match data {
|
||||
Data::BounceEvent(_) => {}
|
||||
Data::DisconnectEvent(_) => {}
|
||||
|
|
|
|||
|
|
@ -1,35 +1,3 @@
|
|||
macro_rules! some_or_return {
|
||||
($e:expr) => {
|
||||
match $e {
|
||||
Some(result) => result,
|
||||
None => return,
|
||||
}
|
||||
};
|
||||
($e:expr, $ret:expr) => {
|
||||
match $e {
|
||||
Some(result) => result,
|
||||
None => return $ret,
|
||||
}
|
||||
};
|
||||
}
|
||||
pub(crate) use some_or_return;
|
||||
|
||||
macro_rules! ok_or_return {
|
||||
($e:expr) => {
|
||||
match $e {
|
||||
Ok(result) => result,
|
||||
Err(_) => return,
|
||||
}
|
||||
};
|
||||
($e:expr, $ret:expr) => {
|
||||
match $e {
|
||||
Ok(result) => result,
|
||||
Err(_) => return $ret,
|
||||
}
|
||||
};
|
||||
}
|
||||
pub(crate) use ok_or_return;
|
||||
|
||||
// TODO Get rid of this macro as much as possible
|
||||
macro_rules! logging_unwrap {
|
||||
($e:expr) => {
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ use toss::widgets::BoxedAsync;
|
|||
use toss::{Terminal, WidgetExt};
|
||||
|
||||
use crate::logger::{LogMsg, Logger};
|
||||
use crate::macros::{logging_unwrap, ok_or_return, some_or_return};
|
||||
use crate::macros::logging_unwrap;
|
||||
use crate::util::InfallibleExt;
|
||||
use crate::vault::Vault;
|
||||
|
||||
|
|
@ -130,11 +130,13 @@ impl Ui {
|
|||
lock: Weak<FairMutex<()>>,
|
||||
) -> crossterm::Result<()> {
|
||||
loop {
|
||||
let lock = some_or_return!(lock.upgrade(), Ok(()));
|
||||
let Some(lock) = lock.upgrade() else { return Ok(()); };
|
||||
let _guard = lock.lock();
|
||||
if crossterm::event::poll(Self::POLL_DURATION)? {
|
||||
let event = crossterm::event::read()?;
|
||||
ok_or_return!(tx.send(UiEvent::Term(event)), Ok(()));
|
||||
if tx.send(UiEvent::Term(event)).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -144,8 +146,12 @@ impl Ui {
|
|||
event_tx: &UnboundedSender<UiEvent>,
|
||||
) {
|
||||
loop {
|
||||
some_or_return!(logger_rx.recv().await);
|
||||
ok_or_return!(event_tx.send(UiEvent::LogChanged));
|
||||
if logger_rx.recv().await.is_none() {
|
||||
return;
|
||||
}
|
||||
if event_tx.send(UiEvent::LogChanged).is_err() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +172,9 @@ impl Ui {
|
|||
if terminal.measuring_required() {
|
||||
let _guard = crossterm_lock.lock();
|
||||
terminal.measure_widths()?;
|
||||
ok_or_return!(self.event_tx.send(UiEvent::GraphemeWidthsChanged), Ok(()));
|
||||
if self.event_tx.send(UiEvent::GraphemeWidthsChanged).is_err() {
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue