base91/
lib.rs

1#![cfg_attr(not(any(feature = "std", test)), no_std)]
2
3//! Joachim Henke's [basE91 encoding](http://base91.sourceforge.net) implementation for Rust.
4//!
5//! Also supports [xml-friendly base91](https://github.com/r-lyeh-archived/base)
6//! implementation by [r-lyeh](https://github.com/r-lyeh), which supports quoting and is
7//! JSON, XML and TSV friendly.
8//!
9//! # Library features
10//!
11//!  - no_std
12//!  - Encode/Decode iterators
13//!  - Canonical (Joachim Hanke) [implementation](http://base91.sourceforge.net)
14//!  - Alternative XML, JSON and TSV friendly ([r-lyeh](https://github.com/r-lyeh)) [implementation](https://github.com/r-lyeh-archived/base)
15//!
16//! # Examples
17//!
18//! ## Using helpers
19//!
20//! ```
21//! let source = "This is a random binary string";
22//!
23//! let encode_as_vec: Vec<u8> = base91::slice_encode(source.as_bytes());
24//! let decode_as_vec: Vec<u8> = base91::slice_decode(&encode_as_vec);
25//!
26//! assert_eq!(
27//!     "nX,<:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z",
28//!     String::from_utf8_lossy(&encode_as_vec)
29//! );
30//!
31//! assert_eq!(
32//!     "This is a random binary string",
33//!     String::from_utf8_lossy(&decode_as_vec)
34//! );
35//! ```
36//!
37//!
38//! ## Using Iterators
39//!
40//! ```
41//! let source = "This is a random binary string";
42//!
43//! let as_vec: Vec<u8> = base91::EncodeIterator::new(source.bytes()).collect();
44//! let as_str: String = base91::EncodeIterator::new(source.bytes()).as_char_iter().collect();
45//!
46//! assert_eq!(
47//!     "nX,<:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z",
48//!     String::from_utf8_lossy(&as_vec)
49//! );
50//!
51//! assert_eq!(
52//!     "nX,<:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z",
53//!     as_str
54//! );
55//! ```
56//!
57//! ## Using Xml Friendly or another specific variation
58//!
59//! Warning!
60//!   If you disable the feature `canonical` and enable the feature `xml-friendly`, then
61//!   `base91::EncodeIterator` and `base91::DecodeIterator` will silently use XmlFriendly variant.
62//!   In turn, all the helper functions use the iterators internally (`slice_encode` and `slice_decode`).
63//!
64//! ```
65//! use base91::iter::{EncodeGenericIterator, DecodeGenericIterator};
66//! use base91::codemap::XmlFriendly;
67//!
68//! let source = "This is a random binary string";
69//!
70//! let encode_as_vec: Vec<u8> = EncodeGenericIterator::<XmlFriendly, _>::new(source.bytes()).collect();
71//! let decode_as_vec: Vec<u8> = DecodeGenericIterator::<XmlFriendly, _>::new(encode_as_vec.iter().copied()).collect();
72//!
73//! assert_eq!(
74//!     "nX,-:WRT%yxtYQ:mbr4JB*H[LR/@Qj{o0aU=Z",
75//!     String::from_utf8_lossy(&encode_as_vec)
76//! );
77//!
78//! assert_eq!(
79//!     "This is a random binary string",
80//!     String::from_utf8_lossy(&decode_as_vec)
81//! );
82//! ```
83
84pub mod codemap;
85pub mod helpers;
86pub mod iter;
87
88pub use helpers::*;
89pub use iter::{DecodeIterator, EncodeIterator};