bincode/config/
trailing.rs1use de::read::SliceReader;
2use {ErrorKind, Result};
3
4pub trait TrailingBytes {
6 fn check_end(reader: &SliceReader) -> Result<()>;
8}
9
10#[derive(Copy, Clone)]
12pub struct AllowTrailing;
13
14#[derive(Copy, Clone)]
17pub struct RejectTrailing;
18
19impl TrailingBytes for AllowTrailing {
20 #[inline(always)]
21 fn check_end(_reader: &SliceReader) -> Result<()> {
22 Ok(())
23 }
24}
25
26impl TrailingBytes for RejectTrailing {
27 #[inline(always)]
28 fn check_end(reader: &SliceReader) -> Result<()> {
29 if reader.is_finished() {
30 Ok(())
31 } else {
32 Err(Box::new(ErrorKind::Custom(
33 "Slice had bytes remaining after deserialization".to_string(),
34 )))
35 }
36 }
37}