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
//! Phenotype building during grammar mapping.
/// Events emitted during grammar derivation, consumed by a [`PhenotypeBuilder`].
/// Trait for building a phenotype from a stream of derivation events.
///
/// The mapper calls `push` for each event during derivation, then
/// calls `finish` to produce the final phenotype.
///
/// # Examples
///
/// ```
/// use evolve::phenotype::{Event, PhenotypeBuilder};
///
/// struct Count(usize);
///
/// #[derive(Default)]
/// struct Counter(usize);
/// impl PhenotypeBuilder<&'static str> for Counter {
/// type Output = Count;
/// fn push(&mut self, event: Event<&str>) {
/// if matches!(event, Event::Terminal(_)) { self.0 += 1; }
/// }
/// fn finish(self) -> Count { Count(self.0) }
/// }
/// ```