qubit_codec_binary/codec/leb128_decode_policy.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::internal::sealed::Sealed;
10
11/// Describes a type-level LEB128 decoding policy.
12///
13/// This trait is sealed because the current LEB128 decoder only supports the
14/// two built-in canonicality modes represented by [`crate::Strict`] and
15/// [`crate::NonStrict`].
16///
17/// # Examples
18///
19/// ```
20/// use qubit_codec_binary::{Leb128DecodePolicy, NonStrict, Strict};
21///
22/// assert!(Strict::STRICT);
23/// assert!(!NonStrict::STRICT);
24/// ```
25///
26/// ```compile_fail
27/// use qubit_codec_binary::Leb128DecodePolicy;
28///
29/// #[derive(Clone, Copy, Default)]
30/// struct ExternalPolicy;
31///
32/// impl Leb128DecodePolicy for ExternalPolicy {
33/// const STRICT: bool = false;
34/// }
35/// ```
36pub trait Leb128DecodePolicy: Sealed + Copy + Default {
37 /// Whether this policy rejects non-canonical encodings.
38 const STRICT: bool;
39}