chore(step): optimize positive and rename it

This commit is contained in:
TD-Sky 2023-09-24 16:35:56 +08:00
parent d8ac32f1fd
commit 5665096094
2 changed files with 8 additions and 6 deletions

View file

@ -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;
}

View file

@ -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<isize> for Step {
#[inline]
fn from(n: isize) -> Self { Self::Fixed(n) }
}
impl From<usize> 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,
}
}
}