1#![doc = include_str!("../README.md")]
2#![cfg_attr(not(feature = "std"), no_std)]
3#![cfg_attr(docsrs, feature(doc_cfg))]
4#![cfg_attr(docsrs, allow(unused_attributes))]
5#![deny(missing_docs)]
6
7#[cfg(all(not(feature = "std"), feature = "alloc"))]
8extern crate alloc as std;
9
10#[cfg(feature = "std")]
11extern crate std;
12
13pub use varing::Varint;
14
15pub use chunk::*;
16pub use chunk_mut::*;
17
18pub mod error;
20
21macro_rules! non_zero {
22 ($($size:literal),+$(,)?) => {
23 paste::paste! {
24 $(
25 const [<NON_ZERO_ $size>]: ::core::num::NonZeroUsize = core::num::NonZeroUsize::new($size).expect(concat!($size, "is non-zero"));
26 )*
27 }
28 };
29}
30
31non_zero!(1);
32
33mod chunk;
34mod chunk_mut;
35
36#[cold]
38fn panic_advance(error_info: &error::TryAdvanceError) -> ! {
39 panic!(
40 "advance out of bounds: the len is {} but advancing by {}",
41 error_info.available(),
42 error_info.requested()
43 );
44}
45
46#[inline]
49const fn must_non_zero(size: usize) -> core::num::NonZeroUsize {
50 match core::num::NonZeroUsize::new(size) {
51 Some(nz) => nz,
52 None => panic!("Already checked value is non-zero"),
53 }
54}
55
56#[test]
57#[should_panic]
58fn test_must_non_zero_panic() {
59 must_non_zero(0);
60}