From 4e69eb63900c37ae94ffce776748cd214de967f8 Mon Sep 17 00:00:00 2001 From: elkowar <5300871+elkowar@users.noreply.github.com> Date: Sat, 3 Oct 2020 20:37:22 +0200 Subject: [PATCH] Fix issues in current nightly by removing try_match --- src/config/element.rs | 21 ++++++++++----------- src/value.rs | 26 ++++++++++++++++---------- 2 files changed, 26 insertions(+), 21 deletions(-) diff --git a/src/config/element.rs b/src/config/element.rs index 5f3b630..e7fae0b 100644 --- a/src/config/element.rs +++ b/src/config/element.rs @@ -1,5 +1,4 @@ use super::*; -use itertools::Itertools; use crate::value::AttrValue; use crate::with_text_pos_context; @@ -85,16 +84,16 @@ impl WidgetUse { //) //} - //pub fn text_with_var_refs(elements: Vec) -> Self { - //dbg!(WidgetUse { - //name: "layout".to_owned(), - //attrs: hashmap! { - //"halign".to_owned() => AttrValue::Concrete(PrimitiveValue::String("center".to_owned())), - //"space-evenly".to_owned() => AttrValue::Concrete(PrimitiveValue::String("false".to_owned())), - //}, - //children: elements.into_iter().map(WidgetUse::simple_text).collect(), - //}) - //} + pub fn text_with_var_refs(elements: Vec) -> Self { + dbg!(WidgetUse { + name: "layout".to_owned(), + attrs: hashmap! { + "halign".to_owned() => AttrValue::Concrete(PrimitiveValue::String("center".to_owned())), + "space-evenly".to_owned() => AttrValue::Concrete(PrimitiveValue::String("false".to_owned())), + }, + children: elements.into_iter().map(WidgetUse::simple_text).collect(), + }) + } pub fn get_attr(&self, key: &str) -> Result<&AttrValue> { self.attrs diff --git a/src/value.rs b/src/value.rs index ef29688..bbf9482 100644 --- a/src/value.rs +++ b/src/value.rs @@ -110,22 +110,28 @@ pub enum AttrValue { impl AttrValue { pub fn as_string(&self) -> Result { - try_match!(AttrValue::Concrete(x) = self) - .map_err(|e| anyhow!("{:?} is not a string", e))? - .as_string() + match self { + AttrValue::Concrete(x) => Ok(x.as_string()?), + _ => Err(anyhow!("{:?} is not a string", self)), + } } pub fn as_f64(&self) -> Result { - try_match!(AttrValue::Concrete(x) = self) - .map_err(|e| anyhow!("{:?} is not an f64", e))? - .as_f64() + match self { + AttrValue::Concrete(x) => Ok(x.as_f64()?), + _ => Err(anyhow!("{:?} is not an f64", self)), + } } pub fn as_bool(&self) -> Result { - try_match!(AttrValue::Concrete(x) = self) - .map_err(|e| anyhow!("{:?} is not a bool", e))? - .as_bool() + match self { + AttrValue::Concrete(x) => Ok(x.as_bool()?), + _ => Err(anyhow!("{:?} is not a bool", self)), + } } pub fn as_var_ref(&self) -> Result<&String> { - try_match!(AttrValue::VarRef(x) = self).map_err(|e| anyhow!("{:?} is not a VarRef", e)) + match self { + AttrValue::VarRef(x) => Ok(x), + _ => Err(anyhow!("{:?} is not a VarRef", self)), + } } /// parses the value, trying to turn it into VarRef,