data_classes/
lib.rs

1pub mod derive {
2    pub use data_classes_derive::*;
3}
4
5pub mod deps {
6    #[cfg(feature = "rand")]
7    pub use rand;
8
9    #[cfg(feature = "serde")]
10    pub extern crate serde;
11
12    #[cfg(feature = "rkyv")]
13    pub use rkyv;
14
15    #[cfg(feature = "bytemuck")]
16    pub use bytemuck;
17}
18
19/// Trait for enums that can get the previous variant in a circular manner.
20pub trait ToPrev: Sized {
21    /// Gets the previous variant.
22    fn get_prev(&self) -> Self;
23
24    /// Switches to the previous variant.
25    fn switch_to_prev(&mut self) {
26        *self = self.get_prev();
27    }
28}
29
30/// Trait for enums that can get the next variant in a circular manner.
31pub trait ToNext: Sized {
32    /// Gets the next variant.
33    fn get_next(&self) -> Self;
34
35    /// Switches to the next variant.
36    fn switch_to_next(&mut self) {
37        *self = self.get_next();
38    }
39}
40
41/// Trait for enums that can get a random variant.
42#[cfg(feature = "rand")]
43pub trait ToRandom: Sized {
44    /// Gets a random variant.
45    fn random<R: rand::Rng + ?Sized>(rng: &mut R) -> Self;
46
47    /// Gets a random variant.
48    fn get_random<R: rand::Rng + ?Sized>(&self, rng: &mut R) -> Self {
49        Self::random(rng)
50    }
51
52    /// Switches to a random variant.
53    fn switch_to_random<R: rand::Rng + ?Sized>(&mut self, rng: &mut R) {
54        *self = Self::random(rng);
55    }
56}