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    /// Gets the previous variant.
6    fn get_prev(&self) -> Self;
7
8    /// Switches to the previous variant.
9    fn switch_to_prev(&mut self) {
10        *self = self.get_prev();
11    }
12}
13
14/// Trait for enums that can get the next variant in a circular manner.
15pub trait ToNext: Sized {
16    /// Gets the next variant.
17    fn get_next(&self) -> Self;
18
19    /// Switches to the next variant.
20    fn switch_to_next(&mut self) {
21        *self = self.get_next();
22    }
23}
24
25/// Trait for enums that can get a random variant.
26#[cfg(feature = "rand")]
27pub trait ToRandom: Sized {
28    /// Gets a random variant.
29    fn random<R: rand::Rng + ?Sized>(rng: &mut R) -> Self;
30
31    /// Gets a random variant.
32    fn get_random<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Self {
33        Self::random(rng)
34    }
35
36    /// Switches to a random variant.
37    fn switch_to_random<R: rand::Rng + ?Sized>(&mut self, rng: &mut R) {
38        *self = Self::random(rng);
39    }
40}