From: Ian Jackson Date: Sun, 4 Feb 2024 18:32:19 +0000 (+0000) Subject: Regularise Paragraph::add and introduce Paragraph::push X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=84dad3ad02bbd6f1d8aa23fbcd4cbf35bddd4bfc;p=mastodonochrome.git Regularise Paragraph::add and introduce Paragraph::push --- diff --git a/src/login.rs b/src/login.rs index ab64a2f..33baf3e 100644 --- a/src/login.rs +++ b/src/login.rs @@ -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; diff --git a/src/text.rs b/src/text.rs index 3f86775..ea8a375 100644 --- a/src/text.rs +++ b/src/text.rs @@ -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 Add for Paragraph { + type Output = Paragraph; + + fn add(mut self, text: T) -> Self { + self.push(text); + self + } +} + #[test] fn test_para_build() { assert_eq!(