#base64 #const-fn #codec #constant #no-std

no-std const_base

Decoding/encoding base 64/32/16 strings at compile-time

4 releases

0.2.0 Dec 5, 2022
0.1.2 Aug 15, 2021
0.1.1 Aug 12, 2021
0.1.0 Aug 10, 2021

#1533 in Encoding

Download history 7/week @ 2024-07-20 26/week @ 2024-07-27 6/week @ 2024-08-10 60/week @ 2024-08-24 76/week @ 2024-08-31 26/week @ 2024-09-07 83/week @ 2024-09-14 207/week @ 2024-09-21 153/week @ 2024-09-28 128/week @ 2024-10-05 10/week @ 2024-10-12 30/week @ 2024-11-02

51 downloads per month

Zlib license

98KB
2K SLoC

Rust crates-io api-docs

For decoding/encoding base 64/32/16 strings at compile-time.

Examples

Encoding

use const_base::{encode_as_str, Config};

{
    // the encoding macros can take both `&str` and `&[u8]` constants.
    const OUTA: &str = encode_as_str!("foo", Config::B64);
    const OUTB: &str = encode_as_str!(b"foo", Config::B64);
    
    assert_eq!(OUTA, "Zm9v");
    assert_eq!(OUTB, "Zm9v");
}
{
    const BYTES: &[u8] = b"hello";

    // the encoding macros can encode_as_str non-literal constants
    const OUT: &str = encode_as_str!(BYTES, Config::B64_URL_SAFE);
    
    assert_eq!(OUT, "aGVsbG8=");
}

Decoding

use const_base::{decode, Config};

{
    const OUT: &[u8] = decode!("MZXW6===", Config::B32);
    
    assert_eq!(OUT, b"foo");
}
{
    const BYTES: &[u8] = b"f000";

    // this macro can decode non-literal constants
    const OUT: &[u8] = decode!(BYTES, Config::HEX);
    
    assert_eq!(OUT, &[0xF0, 0x00]);
}

No-std support

const_base is #![no_std], it can be used anywhere Rust can be used.

Minimum Supported Rust Version

const_base requires Rust 1.64.0.

Dependencies

~215KB

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy