weakauras_codec_base64/lib.rs
1// Copyright 2020-2025 Velithris
2// SPDX-License-Identifier: MIT
3
4//! This library provides heavily optimized routines for decoding and encoding
5//! base64 used for [WeakAuras]-compatible strings.
6//!
7//! Why does this library exist?
8//! Base64 used in WeakAuras packs bits in a non-standard way,
9//! this makes it impossible to use existing implementations,
10//! even if they do support custom alphabets.
11//!
12//! # Decoding example
13//!
14//! This is how you can use the library to decode base64-encoded data.
15//!
16#![cfg_attr(feature = "alloc", doc = "```")]
17#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
18//! use weakauras_codec_base64::{DecodeError, decode_to_vec};
19//!
20//! fn main() -> Result<(), DecodeError> {
21//! assert_eq!(decode_to_vec(b"ivgBS9glGC3BYXgzHa")?, b"Hello, world!");
22//! Ok(())
23//! }
24//! ```
25//!
26//! # Encoding example
27//!
28//! This is how you can use the library to encode data as base64.
29//!
30#![cfg_attr(feature = "alloc", doc = "```")]
31#![cfg_attr(not(feature = "alloc"), doc = "```ignore")]
32//! use weakauras_codec_base64::{EncodeError, encode_to_string};
33//!
34//! fn main() -> Result<(), EncodeError> {
35//! assert_eq!(encode_to_string(b"Hello, world!")?, "ivgBS9glGC3BYXgzHa");
36//! Ok(())
37//! }
38//! ```
39//!
40//! # Crate features
41//!
42//! * **std** - Enable features that require the standard library. As of now, it's used only for runtime SIMD feature detection on x86_64 and x86 CPUs. **Enabled** by default.
43//! * **alloc** - Enable APIs that allocate, like `decode_to_vec` and `encode_to_string`. **Enabled** by default.
44//!
45//! [WeakAuras]: https://weakauras.wtf
46
47#![no_std]
48#![deny(missing_docs)]
49
50#[cfg(any(test, feature = "std"))]
51extern crate std;
52
53#[cfg(any(test, feature = "alloc"))]
54extern crate alloc;
55
56mod byte_map;
57/// Decoding routines.
58pub mod decode;
59/// Encoding routines.
60pub mod encode;
61/// Error types.
62pub mod error;
63pub(crate) mod macros;
64pub use decode::{decode_into, decode_into_unchecked};
65pub use encode::{encode_into, encode_into_unchecked};
66pub use error::*;
67
68#[cfg(feature = "alloc")]
69pub use decode::decode_to_vec;
70#[cfg(feature = "alloc")]
71pub use encode::{encode_to_string, encode_to_string_with_prefix};