Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

code optimize #218

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions src/interactive/widgets/footer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub struct FooterProps {

impl Footer {
pub fn render(&self, props: impl Borrow<FooterProps>, area: Rect, buf: &mut Buffer) {
use SortMode::*;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
use SortMode::*;
use SortMode as E;

let FooterProps {
total_bytes,
entries_traversed,
Expand All @@ -39,12 +40,12 @@ impl Footer {
Span::from(format!(
"Sort mode: {} Total disk usage: {} Items: {} {progress} ",
match sort_mode {
SortMode::SizeAscending => "size ascending",
SortMode::SizeDescending => "size descending",
SortMode::MTimeAscending => "modified ascending",
SortMode::MTimeDescending => "modified descending",
SortMode::CountAscending => "items ascending",
SortMode::CountDescending => "items descending",
SizeAscending => "size ascending",
SizeDescending => "size descending",
MTimeAscending => "modified ascending",
MTimeDescending => "modified descending",
CountAscending => "items ascending",
CountDescending => "items descending",
Comment on lines +43 to +48
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This unfortunately is not recommended because it throws away some of the safety features of enums inside match expressions. See: https://www.youtube.com/watch?v=8j_FbjiowvE

Suggested change
SizeAscending => "size ascending",
SizeDescending => "size descending",
MTimeAscending => "modified ascending",
MTimeDescending => "modified descending",
CountAscending => "items ascending",
CountDescending => "items descending",
E::SizeAscending => "size ascending",
E::SizeDescending => "size descending",
E::MTimeAscending => "modified ascending",
E::MTimeDescending => "modified descending",
E::CountAscending => "items ascending",
E::CountDescending => "items descending",

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this hint! I wasn't really seeing it this way just yet, but totally see the point (i.e. as enums are changing their variant names, there is then catch-all variants that show up as warnings for 'unused variables').

},
match total_bytes {
Some(b) => format!("{}", format.display(*b)),
Expand Down
Loading