From cf997e0ffbd42facd482ccfc926e82c932ecf29c Mon Sep 17 00:00:00 2001 From: Greg Heartsfield Date: Sat, 15 Oct 2022 09:17:22 -0500 Subject: [PATCH] wip: parsing --- src/delegation.rs | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/delegation.rs b/src/delegation.rs index d2f4f33..b5aa6e2 100644 --- a/src/delegation.rs +++ b/src/delegation.rs @@ -44,6 +44,19 @@ pub enum Field { Kind, CreatedAt, } +impl TryFrom<&str> for Field { + type Error = Error; + fn try_from(value: &str) -> Result { + if value=="kind" { + Ok(Field::Kind) + } else if value=="created_at" { + Ok(Field::CreatedAt) + } else { + Err(Error::DelegationParseError) + } + } +} + #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)] pub enum Operator { @@ -90,8 +103,12 @@ fn str_to_condition(cs: &str) -> Option { } // match against the regex let caps = RE.captures(cs)?; - let _field =caps.get(0)?; - Some(Condition {field: Field::Kind, operator: Operator::LessThan, values: vec![]}) + let field = caps.get(1)?.as_str().try_into().ok()?; + let _op = caps.get(2)?.as_str(); + let _vals = caps.get(3)?.as_str(); + // convert field string into Field + + Some(Condition {field: field, operator: Operator::GreaterThan, values: vec![]}) }