Skip to content

Commit

Permalink
pattern/deser: move out uuid checking logic from a match
Browse files Browse the repository at this point in the history
Signed-off-by: Tibor Benke <ihrwein@gmail.com>
  • Loading branch information
ihrwein committed Aug 18, 2015
1 parent 5bf2a2c commit 801e031
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions src/matcher/pattern/deser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl serde::de::Visitor for PatternVisitor {
where V: serde::de::MapVisitor
{
let mut name = None;
let mut uuid = None;
let mut uuid: Option<String> = None;
let mut pattern: Option<String> = None;
let mut values: Option<BTreeMap<String, String>> = None;
let mut tags: Option<Vec<String>> = None;
Expand All @@ -72,16 +72,7 @@ impl serde::de::Visitor for PatternVisitor {
loop {
match try!(visitor.visit_key()) {
Some(Field::NAME) => { name = Some(try!(visitor.visit_value())); }
Some(Field::UUID) => {
let value: String = try!(visitor.visit_value());
uuid = match Uuid::parse_str(&value) {
Ok(v) => Some(v),
Err(err) => {
error!("Invalid field 'uuid': uuid={:?} error={}", value, err);
try!(Err(serde::de::Error::missing_field_error("uuid")))
}
}
}
Some(Field::UUID) => { uuid = Some(try!(visitor.visit_value())); }
Some(Field::PATTERN) => { pattern = Some(try!(visitor.visit_value())); }
Some(Field::VALUES) => { values = Some(try!(visitor.visit_value())); }
Some(Field::TAGS) => { tags = Some(try!(visitor.visit_value())); }
Expand All @@ -90,6 +81,21 @@ impl serde::de::Visitor for PatternVisitor {
}
}

let uuid = match uuid {
Some(uuid) => {
match Uuid::parse_str(&uuid) {
Ok(value) => Some(value),
Err(err) => {
error!("Invalid field 'uuid': uuid={:?} error={}", &uuid, err);
None
}
}
},
None => {
None
}
};

let name = match name {
Some(name) => name,
None => try!(visitor.missing_field("name")),
Expand Down

0 comments on commit 801e031

Please sign in to comment.