Skip to main content

qubit_codec_binary/codec/
strict.rs

1// =============================================================================
2//    Copyright (c) 2026 Haixing Hu.
3//
4//    SPDX-License-Identifier: Apache-2.0
5//
6//    Licensed under the Apache License, Version 2.0.
7// =============================================================================
8
9use super::Leb128DecodePolicy;
10
11/// Selects LEB128 decoding that rejects non-canonical integer encodings.
12///
13/// Use this zero-sized policy as the second type parameter of
14/// [`crate::Leb128Codec`] or [`crate::ZigZagCodec`] when input must use its
15/// shortest valid representation. Encoding remains canonical regardless of
16/// the selected policy.
17///
18/// # Examples
19///
20/// ```
21/// use qubit_codec_binary::{Leb128Codec, Strict};
22///
23/// let input = [0x80, 0x00];
24/// let result = unsafe { Leb128Codec::<u16, Strict>::decode(&input, 0) };
25/// assert!(result.is_err());
26/// ```
27#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
28pub struct Strict;
29
30impl super::internal::sealed::Sealed for Strict {}
31
32impl Leb128DecodePolicy for Strict {
33    /// Whether this policy rejects non-canonical encodings.
34    const STRICT: bool = true;
35}