#![cfg_attr(not(feature = "std"), no_std)]
#![forbid(unsafe_code)]
#[cfg(feature = "alloc")]
extern crate alloc;
mod decode;
mod encode;
mod tables;
pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub use decode::{max_decoded_len, DecodeError, DecodeOptions, Decoder};
pub use encode::{max_encoded_len, EncodeError, Encoder, OutputTooSmall};
pub fn encode_into(input: &[u8], output: &mut [u8]) -> Result<usize, OutputTooSmall> {
Encoder::new().encode_into(input, output)
}
pub fn decode_into(
input: &[u8],
output: &mut [u8],
options: DecodeOptions,
) -> Result<usize, DecodeError> {
Decoder::new(options).decode_into(input, output)
}
#[cfg(feature = "alloc")]
pub use encode::encode;
#[cfg(feature = "alloc")]
pub use decode::decode;
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn slice_apis_compile() {
let mut output = [0_u8; 16];
assert!(encode_into(b"input", &mut output).is_ok());
assert_eq!(
decode_into(b"encoded", &mut output, DecodeOptions::new()),
Ok(5)
);
assert_eq!(&output[..5], b"\xfb\x8d\xca\x1d\xab");
}
#[test]
fn version_matches_package_metadata() {
assert_eq!(VERSION, env!("CARGO_PKG_VERSION"));
assert!(!VERSION.is_empty());
}
}