From 79100fc50f4faf700e29eee6c146914c4d54dcd8 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Mon, 6 Apr 2020 23:35:09 -0400 Subject: [PATCH] Introducing a KVPair type --- src/parser/parser.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/parser/parser.rs b/src/parser/parser.rs index 4241b23..aaf384d 100644 --- a/src/parser/parser.rs +++ b/src/parser/parser.rs @@ -119,6 +119,12 @@ enum RValue<'a> { RVLiteral(&'a str), } +#[derive(Clone, Debug, PartialEq)] +struct KVPair<'a> { + key: &'a str, + value: RValue<'a>, +} + /// Any element significant to dust that isn't plain text /// /// These elements are always wrapped in curly braces @@ -179,8 +185,11 @@ fn rvalue(i: &str) -> IResult<&str, RValue> { } /// Parameters for a partial -fn key_value_pair(i: &str) -> IResult<&str, (&str, RValue)> { - separated_pair(key, tag("="), rvalue)(i) +fn key_value_pair(i: &str) -> IResult<&str, KVPair> { + map(separated_pair(key, tag("="), rvalue), |(k, v)| KVPair { + key: k, + value: v, + })(i) } /// Display a value from the context @@ -692,7 +701,10 @@ mod tests { "", ( "foo", - Some(vec![("bar", RValue::RVPath(Path { keys: vec!["baz"] }))]) + Some(vec![KVPair { + key: "bar", + value: RValue::RVPath(Path { keys: vec!["baz"] }) + }]) ) )) );