`Mix` implements ExactSizeIterator but `len()` panics
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Attiva
- Stack tecnologico
- rust
- Ambito
- audio-video-rtc
Direzione di ricerca
Start with src/source/mix.rs and inspect how Mix implements ExactSizeIterator and size_hint(), then read the uniform format converters in src/source/uniform.rs. The report identifies two possible fixes but asks maintainers which they prefer, so first seek a decision on the contract before estimating completion; done means len() no longer panics for the reported inputs and the chosen behavior is covered.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Mix implements ExactSizeIterator, but its size_hint() can't always give an exact upper bound, so the default len() panics. Two same-format buffers are enough:
use rodio::{buffer::SamplesBuffer, nz, Source};
let mix = SamplesBuffer::new(nz!(1), nz!(1), [0.25])
.mix(SamplesBuffer::new(nz!(1), nz!(1), [0.25, 0.5]));
assert_eq!(mix.clone().count(), 2);
let _ = mix.len(); // panics: upper bound of size_hint() is None
The inputs go through the uniform format converters (src/source/uniform.rs), whose upper bound is None here, and ExactSizeIterator::len asserts upper == Some(lower). On master (685e057) this panics in both debug and release.
Two ways I can see to fix it, and I'd like to know which you prefer before opening a PR:
- Remove the
ExactSizeIteratorimpl forMix(src/source/mix.rs). Simple, but it is a breaking change for anyone callinglen(). - Keep the impl and make
size_hint()exact when it can be: both inputs report exact lengths and need no resampling (same rate), so the output length is just the longer input converted to the shared channel count. That keepslen()working for the common case, but the impl would still panic for inputs that need resampling, so it may only move the problem.
I lean towards 1, since an ExactSizeIterator that panics for some inputs breaks its contract. Noticed while reviewing the stream adapters around #915.
- Lingua principale
- Rust
- Stelle
- 2.5k
- Fork
- 338
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
- Nessun Dockerfile né file Docker Compose
- Nessun modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di RustAudio/rodio
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 73/100
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 67/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 46/100
Tutte le issue di RustAudio/rodio
Issue simili
-
bug nvim
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
-
chip:esp32c6 peripheral:dma
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
esp-rs/esp-hal#7037 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
BrettMayson/HEMTT#1445 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
I maintainer di solito rispondono entro 17 giorni
-
bug(c-sdk): boxlite_box_exec does not check runtime liveness before dispatching streaming execApertabug rust SDK & CLI & REST API
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
boxlite-ai/boxlite#3292 ·
I maintainer di solito rispondono entro 1 giorno