`Mix` implements ExactSizeIterator but `len()` panics

Abierto
#947 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
45/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
rust

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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:

  1. Remove the ExactSizeIterator impl for Mix (src/source/mix.rs). Simple, but it is a breaking change for anyone calling len().
  2. 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 keeps len() 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.

Lenguaje dominante
Rust
Estrellas
2.5k
Forks
338
Métricas de merge de PR
Sin PR fusionados en 30 d

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de RustAudio/rodio

Todos los issues de RustAudio/rodio

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.