Coverage Report

Created: 2026-04-12 06:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/rust/registry/src/index.crates.io-1949cf8c6b5b557f/bincode-1.3.3/src/config/trailing.rs
Line
Count
Source
1
use de::read::SliceReader;
2
use {ErrorKind, Result};
3
4
/// A trait for erroring deserialization if not all bytes were read.
5
pub trait TrailingBytes {
6
    /// Checks a given slice reader to determine if deserialization used all bytes in the slice.
7
    fn check_end(reader: &SliceReader) -> Result<()>;
8
}
9
10
/// A TrailingBytes config that will allow trailing bytes in slices after deserialization.
11
#[derive(Copy, Clone)]
12
pub struct AllowTrailing;
13
14
/// A TrailingBytes config that will cause bincode to produce an error if bytes are left over in the slice when deserialization is complete.
15
16
#[derive(Copy, Clone)]
17
pub struct RejectTrailing;
18
19
impl TrailingBytes for AllowTrailing {
20
    #[inline(always)]
21
0
    fn check_end(_reader: &SliceReader) -> Result<()> {
22
0
        Ok(())
23
0
    }
24
}
25
26
impl TrailingBytes for RejectTrailing {
27
    #[inline(always)]
28
0
    fn check_end(reader: &SliceReader) -> Result<()> {
29
0
        if reader.is_finished() {
30
0
            Ok(())
31
        } else {
32
0
            Err(Box::new(ErrorKind::Custom(
33
0
                "Slice had bytes remaining after deserialization".to_string(),
34
0
            )))
35
        }
36
0
    }
37
}