From: Simon Tatham Date: Mon, 1 Jan 2024 13:51:45 +0000 (+0000) Subject: Elide 'foo: foo' in struct literals where possible. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=59138a8e89e5a4f593ebfefef8510a8ed7c80b57;p=mastodonochrome.git Elide 'foo: foo' in struct literals where possible. 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. --- diff --git a/src/client.rs b/src/client.rs index 3a732a0..a56a8d6 100644 --- a/src/client.rs +++ b/src/client.rs @@ -497,7 +497,7 @@ impl Client { match ext { FeedExtend::Initial => { self.feeds.insert(id.clone(), Feed { - ids: ids, + ids, origin: 0, }); } diff --git a/src/coloured_string.rs b/src/coloured_string.rs index 72d3b31..e9ae2f4 100644 --- a/src/coloured_string.rs +++ b/src/coloured_string.rs @@ -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, diff --git a/src/config.rs b/src/config.rs index 6308468..100c853 100644 --- a/src/config.rs +++ b/src/config.rs @@ -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, } } diff --git a/src/editor.rs b/src/editor.rs index 65178e0..2b1154c 100644 --- a/src/editor.rs +++ b/src/editor.rs @@ -536,10 +536,10 @@ impl BottomLineEditorOverlay { { let promptwidth = prompt.width(); BottomLineEditorOverlay { - prompt: prompt, + prompt, promptwidth, ed: SingleLineEditor::new(), - result: result, + result, } } } diff --git a/src/file.rs b/src/file.rs index e5276aa..c2c7e58 100644 --- a/src/file.rs +++ b/src/file.rs @@ -205,7 +205,7 @@ impl File { }; let mut contents = FileContents { - source: source, + source, header: FileHeader::new(desc), extender, origin: 0, @@ -218,7 +218,7 @@ impl File { 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, diff --git a/src/text.rs b/src/text.rs index 3388f26..512c3e3 100644 --- a/src/text.rs +++ b/src/text.rs @@ -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(), } } diff --git a/src/tui.rs b/src/tui.rs index 32a580d..9a9b787 100644 --- a/src/tui.rs +++ b/src/tui.rs @@ -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, }