Compare commits

..

1 Commits

Author SHA1 Message Date
link2xt
00357b3883 refactor: use some more let..else 2026-05-10 16:21:02 +02:00
4 changed files with 13 additions and 25 deletions

View File

@@ -1,9 +1,3 @@
#!/bin/sh
# Run clippy for all Rust code in the project.
#
# To check, run
# scripts/clippy.sh
#
# To automatically fix warnings, run
# scripts/clippy.sh --fix --allow-dirty
cargo clippy --workspace --all-targets --all-features "$@" -- -D warnings
cargo clippy --workspace --all-targets --all-features -- -D warnings

View File

@@ -427,18 +427,16 @@ mod tests {
let self_chat = ctx1.get_self_chat().await;
let msgs = get_chat_msgs(&ctx1, self_chat.id).await.unwrap();
assert_eq!(msgs.len(), 2);
let msgid = match msgs.first().unwrap() {
ChatItem::Message { msg_id } => msg_id,
_ => panic!("wrong chat item"),
let ChatItem::Message { msg_id } = msgs.first().unwrap() else {
panic!("wrong chat item");
};
let msg = Message::load_from_db(&ctx1, *msgid).await.unwrap();
let msg = Message::load_from_db(&ctx1, *msg_id).await.unwrap();
let text = msg.get_text();
assert_eq!(text, "hi there");
let msgid = match msgs.get(1).unwrap() {
ChatItem::Message { msg_id } => msg_id,
_ => panic!("wrong chat item"),
let ChatItem::Message { msg_id } = msgs.get(1).unwrap() else {
panic!("wrong chat item");
};
let msg = Message::load_from_db(&ctx1, *msgid).await.unwrap();
let msg = Message::load_from_db(&ctx1, *msg_id).await.unwrap();
let path = msg.get_file(&ctx1).unwrap();
assert_eq!(

View File

@@ -704,10 +704,10 @@ async fn test_parse_ndn_group_msg() -> Result<()> {
assert_eq!(msg.state, MessageState::OutFailed);
let msgs = chat::get_chat_msgs(&t, msg.chat_id).await?;
let ChatItem::Message { msg_id } = *msgs.last().unwrap() else {
panic!("Wrong item type");
};
assert_eq!(msg_id, msg.id);
assert!(matches!(
*msgs.last().unwrap(),
ChatItem::Message { msg_id } if msg_id == msg.id
));
Ok(())
}
@@ -1598,9 +1598,7 @@ async fn test_in_reply_to() {
// Load the first message from the same chat.
let msgs = chat::get_chat_msgs(&t, msg.chat_id).await.unwrap();
let msg_id = if let ChatItem::Message { msg_id } = msgs.first().unwrap() {
msg_id
} else {
let ChatItem::Message { msg_id } = msgs.first().unwrap() else {
panic!("Wrong item type");
};

View File

@@ -1557,9 +1557,7 @@ pub(crate) async fn get_chat_msg(
asserted_msgs_count,
msgs.len()
);
let msg_id = if let ChatItem::Message { msg_id } = msgs[index] {
msg_id
} else {
let ChatItem::Message { msg_id } = msgs[index] else {
panic!("Wrong item type");
};
Message::load_from_db(&t.ctx, msg_id).await.unwrap()