From: Simon Tatham Date: Tue, 9 Jan 2024 06:47:55 +0000 (+0000) Subject: Get rid of ColouredStringSlice::to_owned() completely. X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=cb22ce516eaa9f3722941d219c8908069969acc0;p=mastodonochrome.git Get rid of ColouredStringSlice::to_owned() completely. It's superseded by the impl of From for ColouredString, which means now if you want to turn a ColouredStringSlice into an owned string, you can either say ColouredString::from(slice) or slice.into() at your option. And I haven't found any cases where I had to use the more verbose of the two. --- diff --git a/src/coloured_string.rs b/src/coloured_string.rs index b36c2fc..eb3906c 100644 --- a/src/coloured_string.rs +++ b/src/coloured_string.rs @@ -152,8 +152,6 @@ impl<'a> ColouredStringSlice<'a> { ColouredStringSlice { text, colours } } - - pub fn to_owned(&self) -> ColouredString { self.clone().into() } } // We want to be able to use the + operator to concatenate any two diff --git a/src/file.rs b/src/file.rs index d33733e..a11d9b1 100644 --- a/src/file.rs +++ b/src/file.rs @@ -432,7 +432,7 @@ impl File { .render_highlighted(w, highlight, poll_options) { for frag in line.split(w) { - lines.push(frag.to_owned()); + lines.push(frag.into()); } } diff --git a/src/text.rs b/src/text.rs index 8f60dba..fdcc67e 100644 --- a/src/text.rs +++ b/src/text.rs @@ -243,7 +243,7 @@ impl TextFragment for SeparatorLine { suffix; } vec! { - suffix.truncate(width).to_owned() + suffix.truncate(width).into() } } } @@ -279,7 +279,7 @@ impl TextFragment for EditorHeaderSeparator { ColouredString::uniform( &("-".repeat(width - min(2, width)) + "|"), '-', - ).truncate(width).to_owned(), + ).truncate(width).into(), } } } @@ -443,7 +443,7 @@ impl Paragraph { continue; } } - self.words.push(ch.to_owned()); + self.words.push(ch.into()); } } @@ -964,7 +964,7 @@ impl TextFragment for InReplyToLine { } else { first_line.clone() }; - vec! { result.truncate(width).to_owned() } + vec! { result.truncate(width).into() } } } @@ -1017,7 +1017,7 @@ impl TextFragment for VisibilityLine { "Visibility: direct", " rrrrrr"), }; - vec! { line.truncate(width).to_owned() } + vec! { line.truncate(width).into() } } } @@ -1106,7 +1106,7 @@ impl TextFragment for NotificationLog { if rendered_para.len() > 2 { vec! { rendered_para[0].clone(), - rendered_para[1].truncate(width-3).to_owned() + + rendered_para[1].truncate(width-3) + ColouredString::plain("..."), } } else { @@ -1271,7 +1271,7 @@ impl TextFragment for Media { -> Vec { let mut lines: Vec<_> = ColouredString::uniform(&self.url, 'M') - .split(width.saturating_sub(1)).map(|x| x.to_owned()).collect(); + .split(width.saturating_sub(1)).map(|x| x.into()).collect(); for para in &self.description { lines.extend_from_slice(¶.render(width)); } @@ -1670,7 +1670,7 @@ impl TextFragment for MenuKeypressLine { &self.keypress.description; vec! { - line.truncate(width).to_owned() + line.truncate(width).into() } } } @@ -2531,7 +2531,7 @@ impl TextFragment for ExamineUserDisplay { // Trim 3 spaces off, leaving one after the colon let rval = ColouredString::general(&rval.text()[3..], &rval.colours()[3..]); - lines.push(rkey[0].to_owned() + &rval); + lines.push(&rkey[0] + &rval); } else { push_fragment(&mut lines, rkey); push_fragment(&mut lines, rval);