time-rs / time

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

implement `std::iter::Step` for `time::Date` #585

Closed emilioziniades closed 1 year ago

emilioziniades commented 1 year ago

It would be nice to do something like

let start_date = date!(2023 - 01 - 01);
let end_date = date!(2023 - 06 - 01);
for date in start_date..end_date {
    println!("{date}");
}

I naively tried this and got the following compiler error: "the trait Step is not implemented for time::Date"

Having a look at std::iter::Step, it looks pretty straightforward to implement.

If this is something worth doing, I'd be happy to throw together a quick PR.

emilioziniades commented 1 year ago

Nevermind, I didn't see that Step has not been stabilized yet. I am using stable rust, but for some reason the compiler refers to Step. Here's an example

jhpratt commented 1 year ago

The compiler refers to it because it's still used internally there. I assure you that it will implement Step once it's stable! It's one of a number of features I'm tracking, and one I have actually put in some work to get closer to stabilization.

emilioziniades commented 1 year ago

Ah okay cool, thanks for getting back to me. It's a neat trait and looking forward to it being stabilised.