1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//! Gene trait definition.
//!
//! The [`GeneT`] trait is the smallest building block of a chromosome. Every
//! gene carries an integer ID (used for allele identity and duplicate
//! detection) and must be cloneable and thread-safe.
/// Trait that every gene type must implement.
///
/// A gene is a single element inside a chromosome's DNA. Implementations
/// must provide [`GeneT::set_id`]; the remaining methods have sensible
/// defaults.
///
/// # Required bounds
///
/// `Default + Clone + Sync + Send` — genes are created in bulk during
/// initialization and shared across threads by rayon.
///
/// # Examples
///
/// ```rust,no_run
/// use genetic_algorithms::traits::GeneT;
/// use genetic_algorithms::genotypes::Binary;
///
/// // Use a built-in gene type that implements GeneT:
/// let mut gene = <Binary as Default>::default();
/// gene.set_id(5);
/// assert_eq!(gene.id(), 5);
/// ```