From 59163929d33e2dab9b2f2e61cdb7d315b967d00b Mon Sep 17 00:00:00 2001 From: drevilt Date: Thu, 2 Mar 2017 23:16:22 +0100 Subject: [PATCH] update regex to 0.2 (#25) --- Cargo.toml | 2 +- src/parse.rs | 20 ++++++++++---------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 109ced0..ce9cecb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ path = "src/lib.rs" [dependencies] openssl = "0.8" -regex = "0.1" +regex = "0.2" [dev-dependencies] base64 = "0.2" diff --git a/src/parse.rs b/src/parse.rs index 2ded4d4..df5c5ca 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -7,7 +7,7 @@ pub fn parse_authenticate_response(line: String) -> Result { let authenticate_regex = Regex::new("^+(.*)\r\n").unwrap(); for cap in authenticate_regex.captures_iter(line.as_str()) { - let data = cap.at(1).unwrap_or(""); + let data = cap.get(1).map(|x|x.as_str()).unwrap_or(""); return Ok(String::from(data)); } @@ -26,7 +26,7 @@ pub fn parse_capability(lines: Vec) -> Result> { for line in lines.iter() { if capability_regex.is_match(line) { let cap = capability_regex.captures(line).unwrap(); - let capabilities_str = cap.at(1).unwrap(); + let capabilities_str = cap.get(1).unwrap().as_str(); return Ok(capabilities_str.split(' ').map(|x| x.to_string()).collect()); } } @@ -49,7 +49,7 @@ pub fn parse_response(lines: Vec) -> Result> { }; for cap in regex.captures_iter(last_line) { - let response_type = cap.at(2).unwrap_or(""); + let response_type = cap.get(2).map(|x|x.as_str()).unwrap_or(""); match response_type { "OK" => return Ok(lines.clone()), "BAD" => return Err(Error::BadResponse(lines.clone())), @@ -87,25 +87,25 @@ pub fn parse_select_or_examine(lines: Vec) -> Result { for line in lines.iter() { if exists_regex.is_match(line) { let cap = exists_regex.captures(line).unwrap(); - mailbox.exists = cap.at(1).unwrap().parse::().unwrap(); + mailbox.exists = cap.get(1).unwrap().as_str().parse::().unwrap(); } else if recent_regex.is_match(line) { let cap = recent_regex.captures(line).unwrap(); - mailbox.recent = cap.at(1).unwrap().parse::().unwrap(); + mailbox.recent = cap.get(1).unwrap().as_str().parse::().unwrap(); } else if flags_regex.is_match(line) { let cap = flags_regex.captures(line).unwrap(); - mailbox.flags = cap.at(1).unwrap().to_string(); + mailbox.flags = cap.get(1).unwrap().as_str().to_string(); } else if unseen_regex.is_match(line) { let cap = unseen_regex.captures(line).unwrap(); - mailbox.unseen = Some(cap.at(1).unwrap().parse::().unwrap()); + mailbox.unseen = Some(cap.get(1).unwrap().as_str().parse::().unwrap()); } else if uid_validity_regex.is_match(line) { let cap = uid_validity_regex.captures(line).unwrap(); - mailbox.uid_validity = Some(cap.at(1).unwrap().parse::().unwrap()); + mailbox.uid_validity = Some(cap.get(1).unwrap().as_str().parse::().unwrap()); } else if uid_next_regex.is_match(line) { let cap = uid_next_regex.captures(line).unwrap(); - mailbox.uid_next = Some(cap.at(1).unwrap().parse::().unwrap()); + mailbox.uid_next = Some(cap.get(1).unwrap().as_str().parse::().unwrap()); } else if permanent_flags_regex.is_match(line) { let cap = permanent_flags_regex.captures(line).unwrap(); - mailbox.permanent_flags = Some(cap.at(1).unwrap().to_string()); + mailbox.permanent_flags = Some(cap.get(1).unwrap().as_str().to_string()); } }