Individuals

Nothing special, especially by this point in the book. The random() -> Self functions are a touch fragile because you can't query an enumeration for its total number of fields, meaning that if we add or remove a field from Modifier, for instance, we also have to remember to update gen_range(0, 7) appropriately. Removal is not so bad, the compiler will complain some, but addition is easy to forget and overlook.

Let's now look at the individual module. The bulk of the code is in src/individual/mod.rs. The struct for Individual is very short:

#[derive(Debug)]
pub struct Individual {
    chromosome: Vec<Option<Instruction>>,
}

An Individual is a chromosome and little else, a vector of instructions just as we discussed. The functions on ...

Get Hands-On Concurrency with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.