-
-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TimeSeries
implements core::iter::ExactSizeIterator
but doesn't provide upper bound on size_hint
#131
Comments
Hi there,
Thanks! That sure looks like a bug to me, I probably didn't correctly
implement the iterator. I can try to fix this in the coming days, but I'm
on vacation so I'm not coding much right now. I'll try to think of it!
Best,
Chris
…On Thu, Jul 14, 2022, 05:15 Dev Null ***@***.***> wrote:
Hello!
Big fan of this library by the way, love your work.
I wanted to see if I could get the length of a TimeSeries without
collecting into a Vec, but when I call .len() I get the error below.
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `None`,
right: `Some(0)`', /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/iter/traits/exact_size.rs:108:9
stack backtrace:
0: rust_begin_unwind
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/std/src/panicking.rs:584:5
1: core::panicking::panic_fmt
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:143:14
2: core::panicking::assert_failed_inner
3: core::panicking::assert_failed
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/panicking.rs:182:5
4: core::iter::traits::exact_size::ExactSizeIterator::len
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/iter/traits/exact_size.rs:108:9
5: hifitimetest::main
at ./src/bin/hifitimetest.rs:9:10
6: core::ops::function::FnOnce::call_once
at /rustc/fe5b13d681f25ee6474be29d748c65adcd91f69e/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
This seems to be because ExactSizeIterator is expecting an upper bound on
size_hint, which I found to always be None.
If there's no intention of providing .len(), and TimeSeries impls
ExactSizeIterator for some other reason, then that's understandable, but
it's just not clear from the docco.
Here's some code to demo what I mean.
use hifitime::{Duration, Epoch, TimeSeries, Unit::Second};
fn main() {
let start = Epoch::from_gregorian_str("2022-07-14T02:56:11.228271007 UTC").unwrap();
let step = Duration::from_f64(0.5, Second);
let end = start + 100_000_000_000_000 * step;
let times = TimeSeries::exclusive(start, end, step);
dbg!(times.size_hint());
dbg!(times.len());}
my cargo.toml:
[package]...edition = "2021"rust-version = "1.60"
[dependencies]hifitime = "3.2.0"
I get
[src/bin/hifitimetest.rs:8] times.size_hint() = (
0,
None,
)
and then the error above.
> cargo --version
cargo 1.61.0 (a028ae4 2022-04-29)
Thanks!
—
Reply to this email directly, view it on GitHub
<#131>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABEZV2DNWMENUT7CGS7CO3DVT6A4TANCNFSM53QXZ5MQ>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
No worries! enjoy your vacation! |
Sorry for the delay here, I'm working on this now. I hope to get it fixed very soon and it's scheduled in next weekend's release: https://github.com/nyx-space/hifitime/milestone/8 . Let me know if there are other iterator functions you expect to use so I can make sure that those aren't buggy like |
Sorry I only got to this now. I think I've fixed it, and used your test case in the tests themselves (although I changed the number of steps so I could do the math in my head): https://github.com/nyx-space/hifitime/pull/134/files#diff-1ddffea2426780693e1e8ab9f0cf7dcf9361f71126303ebef15d39d919e03cedR173 . I think this is correct but let me know if it isn't. Thanks again for the bug report! |
Hello!
Big fan of this library by the way, love your work.
I wanted to see if I could get the length of a
TimeSeries
without collecting into aVec
, but when I call.len()
I get the error below.This seems to be because
ExactSizeIterator
is expecting an upper bound onsize_hint
, which I found to always beNone
.If there's no intention of providing
.len()
, andTimeSeries
implsExactSizeIterator
for some other reason, then that's understandable, but it's just not clear from the docco.Here's some code to demo what I mean.
my
cargo.toml
:I get
and then the error above.
Not a big deal since you can do
.count()
, it just consumes the iterator and takes a surprisingly long time.version info
Thanks!
The text was updated successfully, but these errors were encountered: