Expand description

A no_std centric implementation of base-x

This requires a nightly compiler to use the array API.

Features used under the ‘unstable’ flag:

  • const_fn_floating_point_arithmetic
  • generic_const_exprs

Implementing a new Alphabet is rather simple:

use smol_base_x::*;
pub struct Base58 {}

impl Base<58> for Base58 {
    const ALPHABET: [u8; 58] = *b"123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
}

Implementing Base will automatically generate a 256 byte LUT, which was chosen over a match statement based off of benchmarks in benches/lut_vs_matches

this lib provides a macro under unstable for generating a match statement equivalent to a LUT, but is mostly useful for when dealing with non-ascii alphabets (which are currently unmaintained).

Modules

encode/decode_arr need to use log10 in order to estimate the size of the output. Since there is no log10 in core or in const scopes, there is are custom implementations of log10. One day (soon™) the log implemenation should be replaced with the proper function from rustlang

Structs

Enums

when decode/encode returns this, it is safe to assume passed in buffer has partially written data. Both functions assume input buffers are zeroed, so do that before re-using the same buffer.

Traits

Base-x for Ascii alphabets (which is most)