From 92c04c606c30631ce9917e0f4fdc66fab19861e5 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 31 Jan 2018 22:24:48 +0100 Subject: [PATCH] Refactor to use AsRef --- lib/etc/libimagutil/src/date.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/etc/libimagutil/src/date.rs b/lib/etc/libimagutil/src/date.rs index 984f028b..b55b8893 100644 --- a/lib/etc/libimagutil/src/date.rs +++ b/lib/etc/libimagutil/src/date.rs @@ -27,8 +27,10 @@ pub fn date_to_string(ndt: &NaiveDate) -> String { ndt.format(NAIVE_DATE_STRING_FORMAT).to_string() } -pub fn date_from_string(s: String) -> Result { - NaiveDate::parse_from_str(&s, NAIVE_DATE_STRING_FORMAT) +pub fn date_from_string(s: S) -> Result + where S: AsRef +{ + NaiveDate::parse_from_str(s.as_ref(), NAIVE_DATE_STRING_FORMAT) } pub const NAIVE_DATETIME_STRING_FORMAT : &'static str = "%Y-%m-%d %H:%M:%S"; @@ -37,7 +39,9 @@ pub fn datetime_to_string(ndt: &NaiveDateTime) -> String { ndt.format(NAIVE_DATETIME_STRING_FORMAT).to_string() } -pub fn datetime_from_string(s: &str) -> Result { - NaiveDateTime::parse_from_str(s, NAIVE_DATETIME_STRING_FORMAT) +pub fn datetime_from_string(s: S) -> Result + where S: AsRef +{ + NaiveDateTime::parse_from_str(s.as_ref(), NAIVE_DATETIME_STRING_FORMAT) }