Introducing a KVPair type

This commit is contained in:
Tom Alexander 2020-04-06 23:35:09 -04:00
parent dd8b4ac28c
commit 79100fc50f
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE
1 changed files with 15 additions and 3 deletions

View File

@ -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"] })
}])
)
))
);