data_classes/
lib.rs

1pub use data_classes_derive::*;
2
3/// Trait for enums that can get the previous variant in a circular manner.
4pub trait ToPrev: Sized {
5    fn get_prev(&self) -> Self;
6
7    fn switch_to_prev(&mut self) {
8        *self = self.get_prev();
9    }
10}
11
12/// Trait for enums that can get the next variant in a circular manner.
13pub trait ToNext: Sized {
14    fn get_next(&self) -> Self;
15
16    fn switch_to_next(&mut self) {
17        *self = self.get_next();
18    }
19}
20
21/// Trait for enums that can get a random variant.
22#[cfg(feature = "rand")]
23pub trait ToRandom: Sized {
24    fn random<R: rand::Rng + ?Sized>(rng: &mut R) -> Self;
25
26    fn get_random<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Self {
27        Self::random(rng)
28    }
29
30    fn switch_to_random<R: rand::Rng + ?Sized>(&mut self, rng: &mut R) {
31        *self = Self::random(rng);
32    }
33}