Skip to content

Fix lifetime invariance in FrameIterator and WindowIterator#1

Draft
Copilot wants to merge 2 commits intomainfrom
copilot/investigate-audio-samples-iterators
Draft

Fix lifetime invariance in FrameIterator and WindowIterator#1
Copilot wants to merge 2 commits intomainfrom
copilot/investigate-audio-samples-iterators

Conversation

Copy link
Copy Markdown

Copilot AI commented Apr 4, 2026

AudioSamples<'a, T> is invariant in 'a, so using a single lifetime for both the reference-to-AudioSamples and its internal data lifetime made .frames() and .windows() unusable from any function taking &AudioSamples<T> — the compiler required the caller to explicitly write &'a AudioSamples<'a, T> with unified lifetimes.

// Previously failed to compile:
fn windowed_mean(audio: &AudioSamples<f32>) -> Vec<f32> {
    audio.windows(nzu!(1024), nzu!(512))
        .map(|w| { /* ... */ })
        .collect()
}
// error: lifetime may not live long enough
//  = note: the struct `AudioSamples<'a, T>` is invariant over the parameter `'a`

Changes

  • FrameIterator<'a, T>FrameIterator<'s, 'a, T> — separates the reference lifetime 's from the data lifetime 'a, with an 'a: 's bound. Matches the pattern ChannelIterator already used correctly.
  • WindowIterator<'a, T>WindowIterator<'s, 'a, T> — same treatment.
  • AudioSamples::frames() / ::windows() — changed from &'a self to &'s self, decoupling the borrow lifetime from the data lifetime.
  • AudioSampleIterators trait — updated frames and windows signatures to match.
  • next() implementations — explicitly copies the stored &'s reference before calling slice_samples to preserve the full 's lifetime through the method call.
  • Regression tests — added test_frames_on_borrow, test_channels_on_borrow, test_windows_on_borrow, and test_frames_and_windows_same_borrowed_ref to guard against recurrence.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • googlechromelabs.github.io
    • Triggering command: /tmp/codeql-scratch-36880336822b49dd/dbs/rust/working/target/debug/build/plotly_static-311d80930e9c4e8d/build-script-build /tmp/codeql-scratch-36880336822b49dd/dbs/rust/working/target/debug/build/plotly_static-311d80930e9c4e8d/build-script-build --hash-style=gnu --as-needed -dynamic-linker /lib64/ld-linux-x86-64.so.2 menter_data-855c8a22ae92df5b/rustchALHME/symbols.o menter_data-855c8a22ae92df5b/build_script_build-855c8a22ae92df5b.build_script_build.bfce194cf466c7c3-cgu.0.rcgu.o menter_data-855c8a22ae92df5b/build_script_build-855c8a22ae92df5b.d6sf3ohay0ur3mrj9cveizfax.rcgu.o -fuse-ld=lld -z 64-REDACTED-linux-gnu/lib/libstd-46d936097e8c5b85.rlib 64-REDACTED-linux-gnu/lib/libpanic_unwind-e462f106b2b26a06.rlib 64-REDACTED-linux-gnu/lib/libobject-926daa94a00ee327.rlib 64-REDACTED-linux-gnu/lib/libmemchr-48d5b0db80402653.rlib 64-REDACTED-linux-gnu/lib/libaddr2line-3367f26bd486b29d.rlib 64-REDACTED-linux-gnu/lib/libgimli-7aeefe72516b1ebd.rlib 64-REDACTED-linux-gnu/lib/libcfg_if-a5addfdc94c3bad3.rlib 64-REDACTED-linux-gnu/lib/librustc_demangle-789fb9c0cb1c7158.rlib 64-REDACTED-linux-gnu/lib/libstd_detect-b16e5cb5eba3e0fd.rlib 64-REDACTED-linux-gnu/lib/libhashbrown-70305b2ec0766fa6.rlib (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Investigate audio samples iterators and lifetime associations Fix lifetime invariance in FrameIterator and WindowIterator Apr 4, 2026
Copilot AI requested a review from jmg049 April 4, 2026 09:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants