korken89 / fugit

`fugit` provides a comprehensive library of `Duration` and `Instant` for the handling of time in embedded systems, doing all it can at compile time.
Apache License 2.0
55 stars 16 forks source link

Implement *Assign ops #19

Closed adamgreig closed 2 years ago

adamgreig commented 2 years ago

Implements +=, -=, =, and /= where appropriate, by using the existing +, -, , and / operators.

This allows for example:

let mut t = MillisDurationU64::millis(100);
t += MillisDurationU64::millis(900);

instead of what's currently required:

let mut t = MillisDurationU64::millis(100);
t = t + MillisDurationU64::millis(900);

Sorry if this has been considered before, I couldn't find any previous discussions. I tried to add it wherever it makes sense alongside an existing operator implementation.

korken89 commented 2 years ago

Awesome, could you add one of each to the tests and update the CHANGELOG?

And thanks for adding! I had completely forgotten this!

adamgreig commented 2 years ago

Thanks! I've added tests (and a few extra tests for the non-assign versions where I couldn't find them, for Duration * u32, Duration / u32, Instant + Duration, Instant - Duration).

korken89 commented 2 years ago

bors merge

bors[bot] commented 2 years ago

Build succeeded: