mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-03-18 15:33:56 +01:00
This commit introduces the 'notification-schema' command to generate a JSON schema of the Notification struct which gets sent when notifying subscribers of updates.
38 lines
862 B
Rust
38 lines
862 B
Rust
use std::num::NonZeroUsize;
|
|
|
|
use clap::ArgEnum;
|
|
use schemars::JsonSchema;
|
|
use serde::Deserialize;
|
|
use serde::Serialize;
|
|
use strum::Display;
|
|
use strum::EnumString;
|
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, Display, EnumString, ArgEnum, JsonSchema)]
|
|
#[strum(serialize_all = "snake_case")]
|
|
pub enum CycleDirection {
|
|
Previous,
|
|
Next,
|
|
}
|
|
|
|
impl CycleDirection {
|
|
#[must_use]
|
|
pub const fn next_idx(&self, idx: usize, len: NonZeroUsize) -> usize {
|
|
match self {
|
|
Self::Previous => {
|
|
if idx == 0 {
|
|
len.get() - 1
|
|
} else {
|
|
idx - 1
|
|
}
|
|
}
|
|
Self::Next => {
|
|
if idx == len.get() - 1 {
|
|
0
|
|
} else {
|
|
idx + 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|