zslayton / cron

A cron expression parser in Rust
Apache License 2.0
376 stars 69 forks source link

feat: implement efficient conversion from String #128

Closed LeoniePhiline closed 1 month ago

LeoniePhiline commented 1 month ago

Previous to this changeset, the implementation of FromStr for Schedule allocated internally.

The same was true for TryFrom<&str> for Schedule, which forwarded to the former.

Library users had no way to prevent the unnecessary double allocation where a heap-allocated String representation is already available, whose ownership could be passed into the Schedule.

This changeset implements efficient conversion from Cow<'_, str>, String and &str.

Borrowed expressions are only heap-allocated if parsing succeeds.

Ownership of owned expressions is passed into the Schedule, circumventing the previous double allocation.

Implements #127