# #34 `read_next_or_eof`'s API prevents buffer reuse

| Field   | Value |
|---------|-------|
| **State** | open |
| **Author** | @DavidVentura |
| **Created** | 2024-04-10 |
| **Updated** | 2024-04-10 |
| **URL** | https://github.com/ruuda/claxon/issues/34 |

---

Hi!
I'm trying to use `claxon` in an embedded environment and would like to reuse the decode buffer, but I'm not figuring out how to do this when I might have multiple frames to decode in a single buffer:
```rust
impl Decode for FlacDecoder {
    fn decode_sample(&mut self, buf: &[u8], out: &mut [i16]) -> Result<usize, anyhow::Error> {
        let mut fr = FrameReader::new(std::io::Cursor::new(buf));
        let mut c = 0;
        let mut v = std::mem::take(&mut self.dec_buf);
        loop {
            if let Ok(Some(block)) = fr.read_next_or_eof(v) {
                for (a, b) in block.stereo_samples() {
                    out[c + 0] = a as i16;
                    out[c + 1] = b as i16;
                    c += 2;
                }
                v = block.into_buffer();
            } else {
                break;
            }
        }
        // self.dec_buf = v;
        // can't do this, `v` was moved into  `read_next_or_eof` 
        // and both the `Err` and `Ok(None)` cases would lose the buffer
        Ok(c)
    }
}
```

I've made [a branch](https://github.com/DavidVentura/claxon/compare/master...DavidVentura:claxon:borrow-api) with an API change which allows passing a mutable reference, but this breaks the `FlacSamples` and `FlacIntoSamples` iterators
