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
use crate::{
chem::Rate,
err::Error,
ord::{Name, Register},
};
use arctk_attr::load;
#[load]
pub struct RateBuilder(f64, Vec<(String, f64)>);
impl RateBuilder {
#[inline]
#[must_use]
pub fn names(&self) -> Vec<String> {
let mut names = Vec::new();
for &(ref n, _) in &self.1 {
names.push(n.to_string());
}
names.sort();
names.dedup();
names
}
}
impl Name for RateBuilder {
type Inst = Rate;
#[inline]
fn reg(self, reg: &Register) -> Result<Self::Inst, Error> {
let mut orders = Vec::with_capacity(self.1.len());
for (name, m) in self.1 {
orders.push((reg.index(&name), m))
}
Ok(Self::Inst::new(self.0, orders))
}
}