wip: parsing

This commit is contained in:
Greg Heartsfield 2022-10-15 09:17:22 -05:00
parent e7f67c8e36
commit cf997e0ffb

View File

@ -44,6 +44,19 @@ pub enum Field {
Kind, Kind,
CreatedAt, CreatedAt,
} }
impl TryFrom<&str> for Field {
type Error = Error;
fn try_from(value: &str) -> Result<Self, Self::Error> {
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)] #[derive(Serialize, Deserialize, PartialEq, Eq, Debug, Clone)]
pub enum Operator { pub enum Operator {
@ -90,8 +103,12 @@ fn str_to_condition(cs: &str) -> Option<Condition> {
} }
// match against the regex // match against the regex
let caps = RE.captures(cs)?; let caps = RE.captures(cs)?;
let _field =caps.get(0)?; let field = caps.get(1)?.as_str().try_into().ok()?;
Some(Condition {field: Field::Kind, operator: Operator::LessThan, values: vec![]}) 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![]})
} }