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