Files
komorebi/komorebi-core/src/cycle_direction.rs
T
LGUG2Z 292bdb282f refactor(clippy): apply all super pedantic lints
Realised that I hadn't turned on super pedantic mode for clippy in the
komorebi-core and komorebic crates. This commit ensures the same clippy
config across all crates and applies the lint suggestions that arose as
a result of turning on the same config everywhere.
2021-08-20 13:26:16 -07:00

35 lines
796 B
Rust

use clap::ArgEnum;
use serde::Deserialize;
use serde::Serialize;
use strum::Display;
use strum::EnumString;
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum)]
#[strum(serialize_all = "snake_case")]
pub enum CycleDirection {
Previous,
Next,
}
impl CycleDirection {
#[must_use]
pub const fn next_idx(&self, idx: usize, len: usize) -> usize {
match self {
CycleDirection::Previous => {
if idx == 0 {
len - 1
} else {
idx - 1
}
}
CycleDirection::Next => {
if idx == len - 1 {
0
} else {
idx + 1
}
}
}
}
}