Fix issues in current nightly by removing try_match

This commit is contained in:
elkowar 2020-10-03 20:37:22 +02:00
parent d05d45e7ab
commit 4e69eb6390
2 changed files with 26 additions and 21 deletions

View file

@ -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<AttrValue>) -> 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<AttrValue>) -> 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

View file

@ -110,22 +110,28 @@ pub enum AttrValue {
impl AttrValue {
pub fn as_string(&self) -> Result<String> {
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<f64> {
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<bool> {
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,