Commit 3629f15e0d

3629f15e0d1fd296888e547280bbad490a60bb86

parent: fd72cf5c4e

Unregistered key

Ulyssa <git@ulyssa.dev> · 2023-01-30 21:51 UTC

Fix newer Clippy warnings for 1.67.0 (#33)

Layout: unified · split

src/commands.rs +1 −1
@@ -40,7 +40,7 @@ fn tag_name(name: String) -> Result<TagName, CommandError> {
40 if let Ok(tag) = name.parse() { 40 if let Ok(tag) = name.parse() {
41 TagName::User(tag) 41 TagName::User(tag)
42 } else { 42 } else {
43 let msg = format!("Invalid user tag name: {}", name); 43 let msg = format!("Invalid user tag name: {name}");
44 44
45 return Err(CommandError::Error(msg)); 45 return Err(CommandError::Error(msg));
46 } 46 }
src/main.rs +4 −4
@@ -455,13 +455,13 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<
455 match worker.login(LoginStyle::Password(password)) { 455 match worker.login(LoginStyle::Password(password)) {
456 Ok(info) => { 456 Ok(info) => {
457 if let Some(msg) = info { 457 if let Some(msg) = info {
458 println!("{}", msg); 458 println!("{msg}");
459 } 459 }
460 460
461 break; 461 break;
462 }, 462 },
463 Err(err) => { 463 Err(err) => {
464 println!("Failed to login: {}", err); 464 println!("Failed to login: {err}");
465 continue; 465 continue;
466 }, 466 },
467 } 467 }
@@ -471,7 +471,7 @@ async fn login(worker: Requester, settings: &ApplicationSettings) -> IambResult<
471} 471}
472 472
473fn print_exit<T: Display, N>(v: T) -> N { 473fn print_exit<T: Display, N>(v: T) -> N {
474 println!("{}", v); 474 println!("{v}");
475 process::exit(2); 475 process::exit(2);
476} 476}
477 477
@@ -532,7 +532,7 @@ fn main() -> IambResult<()> {
532 .thread_name_fn(|| { 532 .thread_name_fn(|| {
533 static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0); 533 static ATOMIC_ID: AtomicUsize = AtomicUsize::new(0);
534 let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst); 534 let id = ATOMIC_ID.fetch_add(1, Ordering::SeqCst);
535 format!("iamb-worker-{}", id) 535 format!("iamb-worker-{id}")
536 }) 536 })
537 .build() 537 .build()
538 .unwrap(); 538 .unwrap();
src/message/mod.rs +2 −2
@@ -134,7 +134,7 @@ impl MessageTimeStamp {
134 match self { 134 match self {
135 MessageTimeStamp::OriginServer(ms) => { 135 MessageTimeStamp::OriginServer(ms) => {
136 let time = millis_to_datetime(*ms).format("%T"); 136 let time = millis_to_datetime(*ms).format("%T");
137 let time = format!(" [{}]", time); 137 let time = format!(" [{time}]");
138 138
139 Span::raw(time).into() 139 Span::raw(time).into()
140 }, 140 },
@@ -343,7 +343,7 @@ impl MessageEvent {
343 .and_then(|r| r.content.reason.as_ref()); 343 .and_then(|r| r.content.reason.as_ref());
344 344
345 if let Some(r) = reason { 345 if let Some(r) = reason {
346 Cow::Owned(format!("[Redacted: {:?}]", r)) 346 Cow::Owned(format!("[Redacted: {r:?}]"))
347 } else { 347 } else {
348 Cow::Borrowed("[Redacted]") 348 Cow::Borrowed("[Redacted]")
349 } 349 }
src/windows/mod.rs +4 −4
@@ -168,7 +168,7 @@ fn append_tags<'a>(tags: &'a Tags, spans: &mut Vec<Span<'a>>, style: Style) {
168 spans.push(Span::styled("User Tag: ", style)); 168 spans.push(Span::styled("User Tag: ", style));
169 spans.push(Span::styled(tag.as_ref(), style)); 169 spans.push(Span::styled(tag.as_ref(), style));
170 }, 170 },
171 tag => spans.push(Span::styled(format!("{:?}", tag), style)), 171 tag => spans.push(Span::styled(format!("{tag:?}"), style)),
172 } 172 }
173 } 173 }
174 174
@@ -594,7 +594,7 @@ impl Window<IambInfo> for IambWindow {
594 } 594 }
595 595
596 fn posn(index: usize, _: &mut ProgramStore) -> IambResult<Self> { 596 fn posn(index: usize, _: &mut ProgramStore) -> IambResult<Self> {
597 let msg = format!("Cannot find indexed buffer (index = {})", index); 597 let msg = format!("Cannot find indexed buffer (index = {index})");
598 let err = UIError::Unimplemented(msg); 598 let err = UIError::Unimplemented(msg);
599 599
600 Err(err) 600 Err(err)
@@ -852,7 +852,7 @@ impl VerifyItem {
852 let device = self.sasv1.other_device(); 852 let device = self.sasv1.other_device();
853 853
854 if let Some(display_name) = device.display_name() { 854 if let Some(display_name) = device.display_name() {
855 format!("Device verification with {} ({})", display_name, state) 855 format!("Device verification with {display_name} ({state})")
856 } else { 856 } else {
857 format!("Device verification with device {} ({})", device.device_id(), state) 857 format!("Device verification with device {} ({})", device.device_id(), state)
858 } 858 }
@@ -958,7 +958,7 @@ impl ListItem<IambInfo> for VerifyItem {
958 lines.push(Spans::from("")); 958 lines.push(Spans::from(""));
959 959
960 for line in format_emojis(emoji).lines() { 960 for line in format_emojis(emoji).lines() {
961 lines.push(Spans::from(format!(" {}", line))); 961 lines.push(Spans::from(format!(" {line}")));
962 } 962 }
963 963
964 lines.push(Spans::from("")); 964 lines.push(Spans::from(""));
src/windows/room/chat.rs +1 −1
@@ -383,7 +383,7 @@ impl ChatState {
383 .map_err(IambError::from)?; 383 .map_err(IambError::from)?;
384 384
385 // Mock up the local echo message for the scrollback. 385 // Mock up the local echo message for the scrollback.
386 let msg = TextMessageEventContent::plain(format!("[Attached File: {}]", name)); 386 let msg = TextMessageEventContent::plain(format!("[Attached File: {name}]"));
387 let msg = MessageType::Text(msg); 387 let msg = MessageType::Text(msg);
388 let msg = RoomMessageEventContent::new(msg); 388 let msg = RoomMessageEventContent::new(msg);
389 389
src/windows/room/mod.rs +1 −4
@@ -132,10 +132,7 @@ impl RoomState {
132 None => format!("{:?}", store.application.get_room_title(self.id())), 132 None => format!("{:?}", store.application.get_room_title(self.id())),
133 }; 133 };
134 134
135 let mut invited = vec![Span::from(format!( 135 let mut invited = vec![Span::from(format!("You have been invited to join {name}"))];
136 "You have been invited to join {}",
137 name
138 ))];
139 136
140 if let Ok(Some(inviter)) = &inviter { 137 if let Ok(Some(inviter)) = &inviter {
141 invited.push(Span::from(" by ")); 138 invited.push(Span::from(" by "));
src/windows/room/scrollback.rs +6 −6
@@ -615,7 +615,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
615 }, 615 },
616 616
617 _ => { 617 _ => {
618 let msg = format!("Unknown editing target: {:?}", motion); 618 let msg = format!("Unknown editing target: {motion:?}");
619 let err = EditError::Unimplemented(msg); 619 let err = EditError::Unimplemented(msg);
620 620
621 return Err(err); 621 return Err(err);
@@ -702,7 +702,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
702 }, 702 },
703 703
704 _ => { 704 _ => {
705 let msg = format!("Unknown motion: {:?}", motion); 705 let msg = format!("Unknown motion: {motion:?}");
706 let err = EditError::Unimplemented(msg); 706 let err = EditError::Unimplemented(msg);
707 707
708 return Err(err); 708 return Err(err);
@@ -790,7 +790,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
790 HistoryAction::Checkpoint => Ok(None), 790 HistoryAction::Checkpoint => Ok(None),
791 HistoryAction::Undo(_) => Err(EditError::Failure("Nothing to undo".into())), 791 HistoryAction::Undo(_) => Err(EditError::Failure("Nothing to undo".into())),
792 HistoryAction::Redo(_) => Err(EditError::Failure("Nothing to redo".into())), 792 HistoryAction::Redo(_) => Err(EditError::Failure("Nothing to redo".into())),
793 _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), 793 _ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))),
794 } 794 }
795 } 795 }
796 796
@@ -847,7 +847,7 @@ impl EditorActions<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
847 847
848 Ok(None) 848 Ok(None)
849 }, 849 },
850 _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), 850 _ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))),
851 } 851 }
852 } 852 }
853} 853}
@@ -874,7 +874,7 @@ impl Editable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
874 Err(err) 874 Err(err)
875 }, 875 },
876 876
877 _ => Err(EditError::Unimplemented(format!("Unknown action: {:?}", act))), 877 _ => Err(EditError::Unimplemented(format!("Unknown action: {act:?}"))),
878 } 878 }
879 } 879 }
880} 880}
@@ -973,7 +973,7 @@ impl Promptable<ProgramContext, ProgramStore, IambInfo> for ScrollbackState {
973 return Err(err); 973 return Err(err);
974 }, 974 },
975 _ => { 975 _ => {
976 let msg = format!("Messages scrollback doesn't support {:?}", act); 976 let msg = format!("Messages scrollback doesn't support {act:?}");
977 let err = EditError::Unimplemented(msg); 977 let err = EditError::Unimplemented(msg);
978 978
979 return Err(err); 979 return Err(err);
src/worker.rs +14 −6
@@ -350,6 +350,7 @@ pub struct ClientWorker {
350 settings: ApplicationSettings, 350 settings: ApplicationSettings,
351 client: Client, 351 client: Client,
352 sync_handle: Option<JoinHandle<()>>, 352 sync_handle: Option<JoinHandle<()>>,
353 rcpt_handle: Option<JoinHandle<()>>,
353} 354}
354 355
355impl ClientWorker { 356impl ClientWorker {
@@ -388,9 +389,10 @@ impl ClientWorker {
388 settings, 389 settings,
389 client: client.clone(), 390 client: client.clone(),
390 sync_handle: None, 391 sync_handle: None,
392 rcpt_handle: None,
391 }; 393 };
392 394
393 let _ = tokio::spawn(async move { 395 tokio::spawn(async move {
394 worker.work(rx).await; 396 worker.work(rx).await;
395 }); 397 });
396 398
@@ -412,6 +414,10 @@ impl ClientWorker {
412 if let Some(handle) = self.sync_handle.take() { 414 if let Some(handle) = self.sync_handle.take() {
413 handle.abort(); 415 handle.abort();
414 } 416 }
417
418 if let Some(handle) = self.rcpt_handle.take() {
419 handle.abort();
420 }
415 } 421 }
416 422
417 async fn run(&mut self, task: WorkerTask) { 423 async fn run(&mut self, task: WorkerTask) {
@@ -685,7 +691,8 @@ impl ClientWorker {
685 ); 691 );
686 692
687 let client = self.client.clone(); 693 let client = self.client.clone();
688 let _ = tokio::spawn(async move { 694
695 self.rcpt_handle = tokio::spawn(async move {
689 // Update the displayed read receipts ever 5 seconds. 696 // Update the displayed read receipts ever 5 seconds.
690 let mut interval = tokio::time::interval(Duration::from_secs(5)); 697 let mut interval = tokio::time::interval(Duration::from_secs(5));
691 698
@@ -695,7 +702,8 @@ impl ClientWorker {
695 let receipts = update_receipts(&client).await; 702 let receipts = update_receipts(&client).await;
696 store.lock().await.application.set_receipts(receipts).await; 703 store.lock().await.application.set_receipts(receipts).await;
697 } 704 }
698 }); 705 })
706 .into();
699 707
700 self.initialized = true; 708 self.initialized = true;
701 } 709 }
@@ -762,7 +770,7 @@ impl ClientWorker {
762 "Failed to create direct message room" 770 "Failed to create direct message room"
763 ); 771 );
764 772
765 let msg = format!("Could not open a room with {}", user); 773 let msg = format!("Could not open a room with {user}");
766 let err = UIError::Failure(msg); 774 let err = UIError::Failure(msg);
767 775
768 Err(err) 776 Err(err)
@@ -1007,12 +1015,12 @@ impl ClientWorker {
1007 let methods = vec![VerificationMethod::SasV1]; 1015 let methods = vec![VerificationMethod::SasV1];
1008 let request = identity.request_verification_with_methods(methods); 1016 let request = identity.request_verification_with_methods(methods);
1009 let _req = request.await.map_err(IambError::from)?; 1017 let _req = request.await.map_err(IambError::from)?;
1010 let info = format!("Sent verification request to {}", user_id); 1018 let info = format!("Sent verification request to {user_id}");
1011 1019
1012 Ok(InfoMessage::from(info).into()) 1020 Ok(InfoMessage::from(info).into())
1013 }, 1021 },
1014 None => { 1022 None => {
1015 let msg = format!("Could not find identity information for {}", user_id); 1023 let msg = format!("Could not find identity information for {user_id}");
1016 let err = UIError::Failure(msg); 1024 let err = UIError::Failure(msg);
1017 1025
1018 Err(err) 1026 Err(err)