chiark / gitweb /
Elide 'foo: foo' in struct literals where possible.
authorSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 13:51:45 +0000 (13:51 +0000)
committerSimon Tatham <anakin@pobox.com>
Mon, 1 Jan 2024 13:51:45 +0000 (13:51 +0000)
Another thing I only just realised: although in general you're
supposed to explicitly say the name of each field you're initialising,
there's a special case where you can leave it out if the name of the
local variable you're initialising it _to_ is exactly the same.
Presumably on the grounds that that still doesn't allow much
confusion, and is terser.

src/client.rs
src/coloured_string.rs
src/config.rs
src/editor.rs
src/file.rs
src/text.rs
src/tui.rs

index 3a732a08e3204b62d7db0423b81abc8a724fba54..a56a8d605b7ce3e8912a5f35b850a57de9b95fba 100644 (file)
@@ -497,7 +497,7 @@ impl Client {
         match ext {
             FeedExtend::Initial => {
                 self.feeds.insert(id.clone(), Feed {
-                    ids: ids,
+                    ids,
                     origin: 0,
                 });
             }
index 72d3b31411bfad4c2ef7d6ad100e9517f3c8e7f8..e9ae2f4acd2c7e0d42cc766b5641c4e929b0cffd 100644 (file)
@@ -70,8 +70,8 @@ impl<'a> ColouredStringSlice<'a> {
         assert_eq!(text.chars().count(), colour.chars().count(),
                    "Mismatched lengths in ColouredStringSlice::general");
         ColouredStringSlice {
-            text: text,
-            colour: colour,
+            text,
+            colour,
         }
     }
 
@@ -189,7 +189,7 @@ impl<'a> ColouredStringSlice<'a> {
     pub fn split(&'a self, width: usize) -> ColouredStringSplitIterator<'a> {
         ColouredStringSplitIterator {
             cs: self.clone(),
-            width: width,
+            width,
             textpos: 0,
             colourpos: 0,
             delivered_empty: false,
@@ -215,7 +215,7 @@ impl<'a> ColouredString {
     pub fn split(&'a self, width: usize) -> ColouredStringSplitIterator<'a> {
         ColouredStringSplitIterator {
             cs: self.slice(),
-            width: width,
+            width,
             textpos: 0,
             colourpos: 0,
             delivered_empty: false,
index 630846877963c29f14eafe35f7d700a55563b91e..100c853c0a31be0c8bea8326f8505e5ee78b2cf3 100644 (file)
@@ -71,13 +71,13 @@ impl ConfigLocation {
         dir.push("mastodonochrome");
 
         Ok(ConfigLocation {
-            dir: dir,
+            dir,
         })
     }
 
     pub fn from_pathbuf(dir: PathBuf) -> Self {
         ConfigLocation {
-            dir: dir,
+            dir,
         }
     }
 
index 65178e0e3296046791d683719dda2bd8287a40e0..2b1154c4726b834834f15cc3592b3485ab2c5dd0 100644 (file)
@@ -536,10 +536,10 @@ impl BottomLineEditorOverlay {
     {
         let promptwidth = prompt.width();
         BottomLineEditorOverlay {
-            prompt: prompt,
+            prompt,
             promptwidth,
             ed: SingleLineEditor::new(),
-            result: result,
+            result,
         }
     }
 }
index e5276aa23e4dca8d271acf595fd79c35fba9ee28..c2c7e583166debc9debc78e125c7a6b22d8e257a 100644 (file)
@@ -205,7 +205,7 @@ impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
         };
 
         let mut contents = FileContents {
-            source: source,
+            source,
             header: FileHeader::new(desc),
             extender,
             origin: 0,
@@ -218,7 +218,7 @@ impl<Type: FileType, Source: FileDataSource> File<Type, Source> {
         let initial_pos = FilePosition::Coarse(contents.last_index() as isize);
 
         let ff = File {
-            contents: contents,
+            contents,
             rendered: HashMap::new(),
             pos: initial_pos,
             last_size: None,
index 3388f26cd48696de547318c83e85883da5fcd9d5..512c3e3d25be6b0c6e66cdb1bf734ef5f3228e93 100644 (file)
@@ -469,7 +469,7 @@ pub struct FileHeader {
 impl FileHeader {
     pub fn new(text: ColouredString) -> Self {
         FileHeader{
-            text: text,
+            text,
         }
     }
 }
@@ -808,9 +808,9 @@ impl NotificationLog {
         }
 
         NotificationLog {
-            timestamp: timestamp,
+            timestamp,
             account_desc: format!("{} ({})", nameline, account),
-            para: para,
+            para,
         }
     }
 
@@ -1040,7 +1040,7 @@ impl FileStatusLine {
     pub fn add(mut self, key: OurKey, description: &str,
                priority: usize) -> Self {
         self.keypresses.push((Keypress {
-                    key: key,
+                    key,
                     description: ColouredString::plain(description)
                 }, priority));
         self
@@ -1305,10 +1305,10 @@ impl MenuKeypressLine {
         let rwid = description.width();
         MenuKeypressLine {
             keypress: Keypress {
-                key: key,
-                description: description,
+                key,
+                description,
             },
-            lwid: lwid,
+            lwid,
             lmaxwid: lwid,
             rmaxwid: rwid,
         }
@@ -1435,12 +1435,12 @@ impl StatusDisplay {
         }).collect();
 
         StatusDisplay {
-            sep: sep,
-            from: from,
-            via: via,
-            irt: irt,
-            content: content,
-            media: media,
+            sep,
+            from,
+            via,
+            irt,
+            content,
+            media,
             blank: BlankLine::new(),
         }
     }
index 32a580d34bd61adb927344b61c026413d6240f56..9a9b787fc025c36c48da4c0c60f106f074dc38a5 100644 (file)
@@ -217,11 +217,11 @@ impl Tui {
         terminal.clear()?;
 
         let mut tui = Tui {
-            terminal: terminal,
+            terminal,
             subthread_sender: sender,
             subthread_receiver: receiver,
             state: TuiLogicalState::new(),
-            client: client,
+            client,
         };
 
         let result = tui.run_inner();
@@ -468,8 +468,8 @@ impl TuiLogicalState {
         let activity_state = main_menu();
 
         TuiLogicalState {
-            activity_stack: activity_stack,
-            activity_state: activity_state,
+            activity_stack,
+            activity_state,
             overlay_activity_state: None,
             last_area: None,
         }