I think it would be useful if, in addition to (or in place of?) the parse_str methods on the data types (Date, DateTime, Duration, Time), there was a FromStr implementation for the types. The implementation can be simple and just call the equivalent existing parse_str methods:
impl FromStr for Duration {
type Err = ParseError;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Self::parse_str(s)
}
}
For Date/DateTime, one question is whether to call parse_str or parse_str_rfc3339. I think it would make sense to call the existing parse_str methods instead of parse_str_rfc3339 since it encompasses the RFC 3339 formats as well, which would be a more permissive FromStr implementation. A user could opt out of this support by calling parse_str_rfc3339 instead.
My use case is using these structs in combination with serde (through serde_with). If they implement both Display and FromStr, they can be serialized/deserialized using DisplayFromStr:
I think it would be useful if, in addition to (or in place of?) the
parse_str
methods on the data types (Date
,DateTime
,Duration
,Time
), there was aFromStr
implementation for the types. The implementation can be simple and just call the equivalent existingparse_str
methods:For
Date
/DateTime
, one question is whether to callparse_str
orparse_str_rfc3339
. I think it would make sense to call the existingparse_str
methods instead ofparse_str_rfc3339
since it encompasses the RFC 3339 formats as well, which would be a more permissiveFromStr
implementation. A user could opt out of this support by callingparse_str_rfc3339
instead.My use case is using these structs in combination with
serde
(throughserde_with
). If they implement bothDisplay
andFromStr
, they can be serialized/deserialized usingDisplayFromStr
: