Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This merge aims to add an interval parsing implementation for watch.
In watch.rs, a new function named
parse_interval
is added, which takes in a&str
and returns a result withDuration
or an error withParseIntError
.The function will first see if the string contains either a '.' or a ',' character. If it does not, it attempts to parse it into seconds and return a duration with that many seconds.
Otherwise, it will attempt to split the string into the seconds and the remainder.
The remainder is then parsed and zero padded. This way we ensure 0.5 becomes 500000000 nanoseconds, and not 5.
If the string has a missing component (such as
.5
or5.
) the function will assume 0.Nanosecond strings that except 9 characters will first be checked if they are valid, then trimmed.
Finally, return the calculated duration or 100 milliseconds. Whichever is longer. This ensures the minimum interval of 0.1 seconds.
Other thoughts:
"a".parse::<u8>()?
to get rust to return aParseIntError
. This is obviously not ideal, but it seems ParseIntError is private to rust, and we'd need to make a custom return type instead. This is possible, but it seemed overkill for this scenario.WATCH_INTERVAL
environment variable has not been implemented yet.