Skip to main content

radiate_core/genome/chromosomes/
mod.rs

1pub mod bit;
2pub mod char;
3pub mod chromosome;
4pub mod float;
5pub mod gene;
6pub mod int;
7pub mod permutation;
8
9pub use bit::{BitChromosome, BitGene};
10pub use char::{CharChromosome, CharGene};
11pub use chromosome::*;
12pub use float::{FloatChromosome, FloatGene};
13pub use gene::{ArithmeticGene, BoundedGene, Gene, NumericGene, Valid};
14pub use int::{IntChromosome, IntGene};
15use num_traits::NumCast;
16pub use permutation::{PermutationChromosome, PermutationGene};
17use radiate_utils::Primitive;
18
19pub trait NumericAllele: Primitive {
20    fn extract<T: NumCast>(self) -> Option<T> {
21        T::from(self)
22    }
23}
24
25macro_rules! impl_numeric_allele {
26    ($($t:ty),*) => {
27        $(
28            impl NumericAllele for $t {}
29
30        )*
31    };
32}
33
34impl_numeric_allele!(f32, f64, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128);
35
36macro_rules! impl_valid {
37    ($($t:ty),*) => {
38        $(
39            impl Valid for $t {
40                #[inline]
41                fn is_valid(&self) -> bool {
42                    true
43                }
44            }
45        )*
46    };
47}
48
49impl_valid!(
50    bool, char, String, isize, usize, u8, u16, u32, u64, u128, i8, i16, i32, i64, i128, f32, f64,
51    &str
52);