summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.md2
-rw-r--r--Cargo.lock2
-rw-r--r--Cargo.toml2
-rw-r--r--src/lib.rs10
-rw-r--r--tests/tests.rs12
5 files changed, 13 insertions, 15 deletions
diff --git a/CHANGES.md b/CHANGES.md
index 8465436..bed6f8d 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -1,5 +1,7 @@
# Change Log
+## 1.3.3
+* revert `ToString` to `&str` for greater efficiency
## 1.3.2
* removed serialized grammar as it made maintenance unwieldy
* added "payperiod" as another synonym for "pay period"
diff --git a/Cargo.lock b/Cargo.lock
index 25eb165..fbb27fe 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -171,7 +171,7 @@ dependencies = [
[[package]]
name = "two_timer"
-version = "1.3.2"
+version = "1.3.3"
dependencies = [
"chrono 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
diff --git a/Cargo.toml b/Cargo.toml
index dd76975..64014c9 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -1,6 +1,6 @@
[package]
name = "two_timer"
-version = "1.3.2"
+version = "1.3.3"
authors = ["dfhoughton <dfhoughton@gmail.com>"]
description="parser for English time expressions"
homepage="https://github.com/dfhoughton/two-timer"
diff --git a/src/lib.rs b/src/lib.rs
index 103b588..c544620 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -589,9 +589,7 @@ lazy_static! {
/// # use two_timer::{parsable};
/// let copacetic = parsable("5/6/69");
/// ```
-pub fn parsable<T: ToString>(phrase: T) -> bool {
- let p = phrase.to_string();
- let phrase = &p;
+pub fn parsable(phrase: &str) -> bool {
if cfg!(feature = "small_grammar") {
SMALL_MATCHER.rx.is_match(phrase) || MATCHER.rx.is_match(phrase)
} else {
@@ -612,12 +610,10 @@ pub fn parsable<T: ToString>(phrase: T) -> bool {
/// # use two_timer::{parse, Config};
/// let (reference_time, _, _) = parse("5/6/69", None).unwrap();
/// ```
-pub fn parse<T: ToString>(
- phrase: T,
+pub fn parse(
+ phrase: &str,
config: Option<Config>,
) -> Result<(NaiveDateTime, NaiveDateTime, bool), TimeError> {
- let p = phrase.to_string();
- let phrase = &p;
let parse = if cfg!(feature = "small_grammar") {
SMALL_MATCHER
.parse(phrase)
diff --git a/tests/tests.rs b/tests/tests.rs
index 8030499..ecf7ccb 100644
--- a/tests/tests.rs
+++ b/tests/tests.rs
@@ -494,7 +494,7 @@ fn this_pay_period() {
let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
for pp in ["pp", "pay period", "payperiod"].iter() {
- let (start, end, _) = parse(format!("this {}", pp), Some(config.clone())).unwrap();
+ let (start, end, _) = parse(format!("this {}", pp).as_ref(), Some(config.clone())).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}
@@ -527,7 +527,7 @@ fn next_pay_period() {
let d1 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
for pp in ["pp", "pay period", "payperiod"].iter() {
- let (start, end, _) = parse(format!("next {}", pp), Some(config.clone())).unwrap();
+ let (start, end, _) = parse(&format!("next {}", pp), Some(config.clone())).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}
@@ -544,7 +544,7 @@ fn last_pay_period() {
let d1 = NaiveDate::from_ymd(1969, 4, 20).and_hms(0, 0, 0);
let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
for pp in ["pp", "pay period", "payperiod"].iter() {
- let (start, end, _) = parse(format!("last {}", pp), Some(config.clone())).unwrap();
+ let (start, end, _) = parse(&format!("last {}", pp), Some(config.clone())).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}
@@ -561,7 +561,7 @@ fn this_pay_period_weird() {
let d1 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
let d2 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
for pp in ["pp", "pay period", "payperiod"].iter() {
- let (start, end, _) = parse(format!("this {}", pp), Some(config.clone())).unwrap();
+ let (start, end, _) = parse(&format!("this {}", pp), Some(config.clone())).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}
@@ -578,7 +578,7 @@ fn next_pay_period_weird() {
let d1 = NaiveDate::from_ymd(1969, 5, 18).and_hms(0, 0, 0);
let d2 = NaiveDate::from_ymd(1969, 6, 1).and_hms(0, 0, 0);
for pp in ["pp", "pay period", "payperiod"].iter() {
- let (start, end, _) = parse(format!("next {}", pp), Some(config.clone())).unwrap();
+ let (start, end, _) = parse(&format!("next {}", pp), Some(config.clone())).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}
@@ -595,7 +595,7 @@ fn last_pay_period_weird() {
let d1 = NaiveDate::from_ymd(1969, 4, 20).and_hms(0, 0, 0);
let d2 = NaiveDate::from_ymd(1969, 5, 4).and_hms(0, 0, 0);
for pp in ["pp", "pay period", "payperiod"].iter() {
- let (start, end, _) = parse(format!("last {}", pp), Some(config.clone())).unwrap();
+ let (start, end, _) = parse(&format!("last {}", pp), Some(config.clone())).unwrap();
assert_eq!(d1, start);
assert_eq!(d2, end);
}