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