Skip to content

Commit

Permalink
[Clippy] Use matches! macro where applicable.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulJuliusMartinez committed Feb 9, 2022
1 parent e9f78b2 commit 0a208b4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 42 deletions.
40 changes: 13 additions & 27 deletions src/flatjson.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@ pub enum OptionIndex {

impl OptionIndex {
pub fn is_nil(&self) -> bool {
match self {
OptionIndex::Nil => true,
_ => false,
}
matches!(self, OptionIndex::Nil)
}

pub fn is_some(&self) -> bool {
Expand Down Expand Up @@ -310,18 +307,14 @@ impl Value {
}

pub fn is_container(&self) -> bool {
match self {
Value::OpenContainer { .. } => true,
Value::CloseContainer { .. } => true,
_ => false,
}
matches!(
self,
Value::OpenContainer { .. } | Value::CloseContainer { .. }
)
}

pub fn is_string(&self) -> bool {
match self {
Value::String => true,
_ => false,
}
matches!(self, Value::String)
}

pub fn container_type(&self) -> Option<ContainerType> {
Expand All @@ -333,17 +326,11 @@ impl Value {
}

pub fn is_opening_of_container(&self) -> bool {
match self {
Value::OpenContainer { .. } => true,
_ => false,
}
matches!(self, Value::OpenContainer { .. })
}

pub fn is_closing_of_container(&self) -> bool {
match self {
Value::CloseContainer { .. } => true,
_ => false,
}
matches!(self, Value::CloseContainer { .. })
}

pub fn is_collapsed(&self) -> bool {
Expand All @@ -359,17 +346,16 @@ impl Value {
}

pub fn is_array(&self) -> bool {
match self {
matches!(
self,
Value::OpenContainer {
container_type: ContainerType::Array,
..
} => true,
Value::CloseContainer {
} | Value::CloseContainer {
container_type: ContainerType::Array,
..
} => true,
_ => false,
}
}
)
}

fn toggle_collapsed(&mut self) {
Expand Down
30 changes: 15 additions & 15 deletions src/viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,21 +194,21 @@ impl JsonViewer {
}

fn should_reset_desired_depth(action: &Action) -> bool {
match action {
Action::NoOp => false,
Action::FocusPrevSibling(_) => false,
Action::FocusNextSibling(_) => false,
Action::ScrollUp(_) => false,
Action::ScrollDown(_) => false,
Action::PageUp(_) => false,
Action::PageDown(_) => false,
Action::MoveFocusedLineToTop => false,
Action::MoveFocusedLineToCenter => false,
Action::MoveFocusedLineToBottom => false,
Action::ToggleMode => false,
Action::ResizeViewerDimensions(_) => false,
_ => true,
}
!matches!(
action,
Action::NoOp
| Action::FocusPrevSibling(_)
| Action::FocusNextSibling(_)
| Action::ScrollUp(_)
| Action::ScrollDown(_)
| Action::PageUp(_)
| Action::PageDown(_)
| Action::MoveFocusedLineToTop
| Action::MoveFocusedLineToCenter
| Action::MoveFocusedLineToBottom
| Action::ToggleMode
| Action::ResizeViewerDimensions(_)
)
}

fn move_up(&mut self, rows: usize) {
Expand Down

0 comments on commit 0a208b4

Please sign in to comment.