Commit ceee996e authored by Scott Abbey's avatar Scott Abbey

Add traits for range structs

parent 822816e4
use regex::Regex;
use version::Identifier;
use std::str::FromStr;
lazy_static! {
static ref REGEX: Regex = {
......@@ -54,12 +55,14 @@ pub struct VersionReq {
pub predicates: Vec<Predicate>,
}
#[derive(PartialEq,Debug)]
pub enum WildcardVersion {
Major,
Minor,
Patch,
}
#[derive(PartialEq,Debug)]
pub enum Op {
Ex, // Exact
Gt, // Greater than
......@@ -71,6 +74,24 @@ pub enum Op {
Wildcard(WildcardVersion), // x.y.*, x.*, *
}
impl FromStr for Op {
type Err = String;
fn from_str(s: &str) -> Result<Op, String> {
match s {
"=" => Ok(Op::Ex),
">" => Ok(Op::Gt),
">=" => Ok(Op::GtEq),
"<" => Ok(Op::Lt),
"<=" => Ok(Op::LtEq),
"~" => Ok(Op::Tilde),
"^" => Ok(Op::Compatible),
_ => Err(String::from("Could not parse Op")),
}
}
}
#[derive(PartialEq,Debug)]
pub struct Predicate {
op: Op,
major: u64,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment