Skip to content

Commit 8b3dca6

Browse files
Added decode_whole
1 parent f9f54c1 commit 8b3dca6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/lib.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,12 @@
1+
pub fn decode_whole<D: bincode::de::Decode<()>, C: bincode::config::Config>(
2+
src: &[u8],
3+
config: C,
4+
) -> Result<D, bincode::error::DecodeError> {
5+
let (t, consumed) = bincode::decode_from_slice(src, config)?;
16

7+
if consumed != src.len() {
8+
return Err(bincode::error::DecodeError::Other("leftover bytes"));
9+
}
10+
11+
Ok(t)
12+
}

0 commit comments

Comments
 (0)