time-rs / time

The most used Rust library for date and time handling.
https://time-rs.github.io
Apache License 2.0
1.1k stars 277 forks source link

Add must_use function attributes #657

Closed cgzones closed 8 months ago

cgzones commented 8 months ago

Annotate several public funtions that either don't modify their original value or only compute a value, except for ones returning Result.

Avoid no-op code such as:

let odt = OffsetDateTime::now_utc();
odt.saturating_add(Duration::SECOND);
jhpratt commented 8 months ago

If there is a specific method you think could be reasonably interpreted as mutating the input that does not already have a #[must_use] attribute, please open an issue to discuss it. Adding it to everything is functionally pointless.

cgzones commented 7 months ago

Is it though? For example std::time::Duration uses the annotation on almost every interface (except for ones returning Result, since Result already comes with an annotation).

jhpratt commented 7 months ago

And I disagree with using it that much. As I said, a method needs to be able to be reasonably interpreted as mutating the input. That is the criteria that I am using. Anything else is a non-starter.