From 587fa6a4a615a28c9822b37bc7ca2d104fe8ec05 Mon Sep 17 00:00:00 2001 From: Taylor Bockman Date: Fri, 15 Dec 2017 17:34:56 -0800 Subject: [PATCH] fix idea --- src/options.rs | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/options.rs b/src/options.rs index 4706e45..4e2d60f 100644 --- a/src/options.rs +++ b/src/options.rs @@ -90,24 +90,35 @@ impl EngineOption { EngineOption { name, option_type, option_data, } } + fn engine_option_data_type_string(&t: EngineOptionDataType) -> String { + match t { + EngineOptionDataType::DefaultVal => String::new("default"), + EngineOptionDataType::Min => String::new("min"), + EngineOptionDataType::Max => String::new("max"), + EngineOptionDataType::Var => String::new("var"), + } + } + + fn engine_option_data_string(&d: EngineOptionData) -> String { + match eod { + EngineOptionData::Int(v) => v.to_string(), + EngineOptionData::Float(v) => v.to_string(), + EngineOptionData::Text(ref v) => v.clone(), + } + } + pub fn option_string(&self) -> String { let mut option_data_string: String = String::new(); + // FIXME: Hash maps are iterated out of order (obviously). In order to guarantee order in the response it'll be + // Easier to test if the key exists (since there are only 3 of them ever), if it does, get the value with + // HashMap::Get, which returns a reference. + // + // Test for the key with HashMap::contains_key. You'll have to match for each instance using the private + // functions above. You will _still_ need to build a string like you did before. for (dt, eod) in self.option_data.iter() { let _: (&EngineOptionDataType, &EngineOptionData) = (dt, eod); - let dts = match dt { - &EngineOptionDataType::DefaultVal => "default", - &EngineOptionDataType::Min => "min", - &EngineOptionDataType::Max => "max", - &EngineOptionDataType::Var => "var", - }; - - let res = match eod { - &EngineOptionData::Int(v) => v.to_string(), - &EngineOptionData::Float(v) => v.to_string(), - &EngineOptionData::Text(ref v) => v.clone(), - }; option_data_string.push_str(&format!("{} {} ", dts, res)); }