chiark / gitweb /
Get rid of ColouredStringSlice::to_owned() completely.
authorSimon Tatham <anakin@pobox.com>
Tue, 9 Jan 2024 06:47:55 +0000 (06:47 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 10 Jan 2024 07:53:54 +0000 (07:53 +0000)
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.

src/coloured_string.rs
src/file.rs
src/text.rs

index b36c2fc101d313c399e8694dd073ca69f942f582..eb3906ca4a2a4adfea7ab9aa6ce8435149ca3a76 100644 (file)
@@ -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
index d33733e4d4c0ae61ca91a921e062b193a3e5f572..a11d9b17847de93ca5723244559624632a0c5810 100644 (file)
@@ -432,7 +432,7 @@ impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
                 .render_highlighted(w, highlight, poll_options)
             {
                 for frag in line.split(w) {
-                    lines.push(frag.to_owned());
+                    lines.push(frag.into());
                 }
             }
 
index 8f60dba72f3a70b3d37b3267fd38268914696434..fdcc67e6ac7cf12f81c824fc0d1f90549007646b 100644 (file)
@@ -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<ColouredString>
     {
         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(&para.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);