diff --git a/crates/dekoder/src/inventory.rs b/crates/dekoder/src/inventory.rs index ab1ce8cde..c46115f20 100644 --- a/crates/dekoder/src/inventory.rs +++ b/crates/dekoder/src/inventory.rs @@ -14,7 +14,9 @@ const HEADER_EXT: &'static str = "*.yaml"; /// Header type in an inventory. pub(crate) trait HeaderT { /// Load from yaml. - fn load_from_yaml(yml: &Yaml) -> Result>; + fn load_from_yaml(yml: &Yaml) -> Result + where + Self: Sized; /// Comparator. fn eq(&self, other: &Self, ulps: i64) -> bool; } @@ -32,7 +34,7 @@ pub(crate) struct Inventory { /// Working directory pub(crate) path: PathBuf, /// Available keys - pub(crate) keys: HashMap>, + pub(crate) keys: HashMap, } impl Inventory { @@ -62,7 +64,7 @@ impl Inventory { } /// List available keys. - pub fn keys(&self) -> Vec<&Box> { + pub fn keys(&self) -> Vec<&K> { let mut ks = Vec::new(); for k in self.keys.values() { ks.push(k); diff --git a/crates/dekoder/src/lib.rs b/crates/dekoder/src/lib.rs index 79b3ce32a..6d986de63 100644 --- a/crates/dekoder/src/lib.rs +++ b/crates/dekoder/src/lib.rs @@ -13,6 +13,8 @@ use yaml_rust2::Yaml; mod inventory; +use crate::inventory::HeaderT; + /// The EKO errors. #[derive(Error, Debug)] pub enum EKOError { @@ -43,7 +45,7 @@ pub struct EvolutionPoint { impl inventory::HeaderT for EvolutionPoint { /// Load from yaml. - fn load_from_yaml(yml: &Yaml) -> Result> { + fn load_from_yaml(yml: &Yaml) -> Result { // work around float representation let scale = yml["scale"].as_f64(); let scale = if scale.is_some() { @@ -58,15 +60,22 @@ impl inventory::HeaderT for EvolutionPoint { let nf = yml["nf"] .as_i64() .ok_or(EKOError::KeyError("because failed to read nf".to_owned()))?; - Ok(Box::new(Self { scale, nf })) + Ok(Self { scale, nf }) } - /// Comparator. + /// (Protected) comparator. fn eq(&self, other: &Self, ulps: i64) -> bool { self.nf == other.nf && approx_eq!(f64, self.scale, other.scale, ulps = ulps) } } +impl EvolutionPoint { + /// Comparator. + pub fn equals(&self, other: &Self, ulps: i64) -> bool { + self.eq(other, ulps) + } +} + /// 4D evolution operator. pub struct Operator { pub op: Array4, @@ -203,7 +212,7 @@ impl EKO { } /// List available evolution points. - pub fn available_operators(&self) -> Vec<&Box> { + pub fn available_operators(&self) -> Vec<&EvolutionPoint> { self.operators.keys() } diff --git a/crates/dekoder/tests/test_load.rs b/crates/dekoder/tests/test_load.rs index d6461cc01..bb999ddb9 100644 --- a/crates/dekoder/tests/test_load.rs +++ b/crates/dekoder/tests/test_load.rs @@ -59,6 +59,8 @@ fn has_operator() { scale: 10000., nf: 4, }; + // it is the one + assert!(ep.equals(eko.available_operators()[0], 64)); assert!(eko.has_operator(&ep, 64)); eko.close(false).unwrap(); }