summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-12-05 00:04:11 +0000
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-12-05 00:04:11 +0000
commit8fdb14af2e8c6951251d7104245fbf5951db110e (patch)
treea75fb3dfb592251a5d7e339d8ea1a4134ccdff0b
parenta8ee97ab7ec2f8a2bc9f46a58bc452b9fcd601f4 (diff)
downloadparsebyregex-8fdb14af2e8c6951251d7104245fbf5951db110e.tar.bz2
Neater to implement FromStr instead of ParseByRegex
-rw-r--r--parsebyregex-example/src/main.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/parsebyregex-example/src/main.rs b/parsebyregex-example/src/main.rs
index b30a3ca..96d4d83 100644
--- a/parsebyregex-example/src/main.rs
+++ b/parsebyregex-example/src/main.rs
@@ -6,10 +6,12 @@ use chrono::prelude::*;
#[derive(Debug)]
struct MyDateTime(DateTime<Utc>);
-impl ParseByRegex for MyDateTime {
- fn parse_by_regex<T: AsRef<str>>(input: T) -> Result<MyDateTime, Box<std::error::Error>> {
+
+impl std::str::FromStr for MyDateTime {
+ type Err = chrono::format::ParseError;
+ fn from_str(input: &str) -> std::result::Result<MyDateTime, Self::Err> {
static DATEFMT: &str = "%Y-%m-%d %H:%M";
- Ok(MyDateTime(Utc.datetime_from_str(input.as_ref(), DATEFMT)?))
+ Ok(MyDateTime(Utc.datetime_from_str(input, DATEFMT)?))
}
}