Commit ceee996e authored by Scott Abbey's avatar Scott Abbey

Add traits for range structs

parent 822816e4
use regex::Regex; use regex::Regex;
use version::Identifier; use version::Identifier;
use std::str::FromStr;
lazy_static! { lazy_static! {
static ref REGEX: Regex = { static ref REGEX: Regex = {
...@@ -54,12 +55,14 @@ pub struct VersionReq { ...@@ -54,12 +55,14 @@ pub struct VersionReq {
pub predicates: Vec<Predicate>, pub predicates: Vec<Predicate>,
} }
#[derive(PartialEq,Debug)]
pub enum WildcardVersion { pub enum WildcardVersion {
Major, Major,
Minor, Minor,
Patch, Patch,
} }
#[derive(PartialEq,Debug)]
pub enum Op { pub enum Op {
Ex, // Exact Ex, // Exact
Gt, // Greater than Gt, // Greater than
...@@ -71,6 +74,24 @@ pub enum Op { ...@@ -71,6 +74,24 @@ pub enum Op {
Wildcard(WildcardVersion), // x.y.*, x.*, * 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 { pub struct Predicate {
op: Op, op: Op,
major: u64, 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