1#![cfg_attr(not(feature = "std"), no_std)]
2#![forbid(unsafe_code)]
3
4#[cfg(feature = "alloc")]
14extern crate alloc;
15
16mod decode;
17mod encode;
18mod tables;
19
20pub const VERSION: &str = env!("CARGO_PKG_VERSION");
22
23pub use decode::{max_decoded_len, DecodeError, DecodeOptions, Decoder};
24pub use encode::{max_encoded_len, EncodeError, Encoder, OutputTooSmall};
25
26pub fn encode_into(input: &[u8], output: &mut [u8]) -> Result<usize, OutputTooSmall> {
30 Encoder::new().encode_into(input, output)
31}
32
33pub fn decode_into(
38 input: &[u8],
39 output: &mut [u8],
40 options: DecodeOptions,
41) -> Result<usize, DecodeError> {
42 Decoder::new(options).decode_into(input, output)
43}
44
45#[cfg(feature = "alloc")]
46pub use encode::encode;
47
48#[cfg(feature = "alloc")]
49pub use decode::decode;
50
51#[cfg(test)]
52mod tests {
53 use super::*;
54
55 #[test]
56 fn slice_apis_compile() {
57 let mut output = [0_u8; 16];
58 assert!(encode_into(b"input", &mut output).is_ok());
59 assert_eq!(
60 decode_into(b"encoded", &mut output, DecodeOptions::new()),
61 Ok(5)
62 );
63 assert_eq!(&output[..5], b"\xfb\x8d\xca\x1d\xab");
64 }
65
66 #[test]
67 fn version_matches_package_metadata() {
68 assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
69 assert!(!VERSION.is_empty());
70 }
71}