We're using this library together with thiserror to provide nicely formatted durations & timestamps in our error messages, for example, like this:
#[derive(Debug, thiserror::Error)]
enum Error {
#[error("operation timed out after {0}")]
Timeout(FormattedDuration),
}
This works great, but limits programmatic usability of the error enum, since once a duration (or system time) is formatted, there is no way to access it again, because the library doesn't expose them. If we ever wanted to programmatically process timeout errors we'd need to store the duration value we're formatting as well, which isn't really nice because we'd be doubling the size of that variant and there is no static guarantee that those values are actually the same.
Therefore this PR adds two accessor methods to the formatting wrappers that expose the time values that are being formatted.
Hey! 👋
First of all, thank you for this great library!
We're using this library together with
thiserror
to provide nicely formatted durations & timestamps in our error messages, for example, like this:This works great, but limits programmatic usability of the error enum, since once a duration (or system time) is formatted, there is no way to access it again, because the library doesn't expose them. If we ever wanted to programmatically process timeout errors we'd need to store the duration value we're formatting as well, which isn't really nice because we'd be doubling the size of that variant and there is no static guarantee that those values are actually the same.
Therefore this PR adds two accessor methods to the formatting wrappers that expose the time values that are being formatted.