Like [`decode`], but saves allocations between calls.
(&mut self, mut bytes: &'a [u8])
| 92 | |
| 93 | /// Like [`decode`], but saves allocations between calls. |
| 94 | pub fn decode<'a, T: Decode<'a>>(&mut self, mut bytes: &'a [u8]) -> Result<T, Error> { |
| 95 | // Safety: Decoders have dangling pointers to `bytes` from previous calls which haven't been |
| 96 | // cleared. This isn't an issue in practice because they remain as pointers in FastSlice and |
| 97 | // aren't dereferenced. If we wanted to be safer we could clear all the decoders but this |
| 98 | // would result in lots of extra code to maintain and a performance/binary size hit. |
| 99 | // To detect misuse we run miri tests/cargo fuzz where bytes goes out of scope between calls. |
| 100 | let decoder = unsafe { self.registry.get_non_static::<T::Decoder>() }; |
| 101 | decoder.populate(&mut bytes, 1)?; |
| 102 | expect_eof(bytes)?; |
| 103 | Ok(decode_inline_never(decoder)) |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | #[cfg(test)] |
no test coverage detected