From 56650960944feb3c37e1db00a4a4df5b3bae3a5d Mon Sep 17 00:00:00 2001 From: TD-Sky Date: Sun, 24 Sep 2023 16:35:56 +0800 Subject: [PATCH] chore(step): optimize `positive` and rename it --- core/src/manager/tab.rs | 2 +- core/src/step.rs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/core/src/manager/tab.rs b/core/src/manager/tab.rs index 25f8b3e6..b9f14c37 100644 --- a/core/src/manager/tab.rs +++ b/core/src/manager/tab.rs @@ -68,7 +68,7 @@ impl Tab { } pub fn arrow(&mut self, step: Step) -> bool { - let ok = if step.positive() { self.current.next(step) } else { self.current.prev(step) }; + let ok = if step.is_positive() { self.current.next(step) } else { self.current.prev(step) }; if !ok { return false; } diff --git a/core/src/step.rs b/core/src/step.rs index ce42743a..7584500d 100644 --- a/core/src/step.rs +++ b/core/src/step.rs @@ -6,6 +6,7 @@ pub enum Step { } impl Default for Step { + #[inline] fn default() -> Self { Self::Fixed(0) } } @@ -22,10 +23,12 @@ impl FromStr for Step { } impl From for Step { + #[inline] fn from(n: isize) -> Self { Self::Fixed(n) } } impl From for Step { + #[inline] fn from(n: usize) -> Self { Self::Fixed(n as isize) } } @@ -46,11 +49,10 @@ impl Step { } #[inline] - pub fn positive(&self) -> bool { - match self { - Self::Fixed(n) if *n > 0 => true, - Self::Percent(n) if *n > 0 => true, - _ => false, + pub fn is_positive(&self) -> bool { + match *self { + Self::Fixed(n) => n > 0, + Self::Percent(n) => n > 0, } } }