`Mix` implements ExactSizeIterator but `len()` panics
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- rust
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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.
- 主要语言
- Rust
- 星标
- 2.5k
- 派生
- 338
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
RustAudio/rodio 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 82/100
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
-
难度 1/5 1 小时以内 新手友好度 73/100
-
难度 3/5 1-2 天 新手友好度 67/100
-
难度 4/5 3-5 天 新手友好度 46/100
相似的 Issue
-
bug nvim
难度 2/5 1-3 小时 新手友好度 74/100
-
chip:esp32c6 peripheral:dma
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
BrettMayson/HEMTT#1445 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 65/100
Choochmeque/tauri-plugin-webdriver#134 ·
维护者通常 17 天内回复
-
bug rust SDK & CLI & REST API
难度 2/5 1-3 小时 新手友好度 75/100
boxlite-ai/boxlite#3292 ·
维护者通常 1 天内回复