chiark / gitweb /
Regularise Paragraph::add and introduce Paragraph::push
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Feb 2024 18:32:19 +0000 (18:32 +0000)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sun, 4 Feb 2024 18:32:19 +0000 (18:32 +0000)
src/login.rs
src/text.rs

index ab64a2f745a0dbcbabd1fd7f4edb220a26d8fd6c..33baf3e6c88af0fd0ac2b38eac71d364ef283106 100644 (file)
@@ -1,6 +1,7 @@
 use email_address::EmailAddress;
 use reqwest::Url;
 use std::cell::RefCell;
+use std::ops::Add;
 use std::rc::Rc;
 use std::str::FromStr;
 use sys_locale::get_locale;
index 3f86775127659eb137cf8bdb391539765760a1b7..ea8a3750a197f73729f873ddfe20769a559c7122 100644 (file)
@@ -3,6 +3,7 @@ use chrono::NaiveDateTime;
 use chrono::{DateTime, Local, Utc};
 use core::cmp::{max, min};
 use std::collections::{BTreeMap, HashSet};
+use std::ops::Add;
 use unicode_width::UnicodeWidthStr;
 
 use super::client::{Client, ClientError};
@@ -532,12 +533,8 @@ impl Paragraph {
         }
     }
 
-    // TODO clippy is right to complain, but I don't think I agree
-    // with the proposed resolution.  We should rename this method to `push`.
-    #[allow(clippy::should_implement_trait)]
-    pub fn add(mut self, text: impl ColouredStringCommon) -> Self {
+    pub fn push(&mut self, text: impl ColouredStringCommon) {
         self.push_text(text, false);
-        self
     }
 
     pub fn clear(&mut self) {
@@ -581,6 +578,15 @@ impl Paragraph {
     }
 }
 
+impl<T: ColouredStringCommon> Add<T> for Paragraph {
+    type Output = Paragraph;
+
+    fn add(mut self, text: T) -> Self {
+        self.push(text);
+        self
+    }
+}
+
 #[test]
 fn test_para_build() {
     assert_eq!(