pub struct Base<const RADIX: usize, const LUT: bool, const PAD: bool, const CASE: bool, CODE> { /* private fields */ }Expand description
๐ฅก A compile-time configurable radix-based encoding scheme.
This struct defines the core behavior for various base encodings,
including Base16, Base32 and Base64.
It converts binary โ text for data transmission/storage.
It is configurable via const generics to support different encoding behaviors, such as lookup tables, padding, and case insensitivity.
ยงType Parameters
RADIX: The numeric radix of the encoding (e.g., 16, 32, 64).LUT: Whether to use a lookup table (true) for fast decoding or a linear search (false) using less memory.PAD: Whether to use padding (=) for encoding output (used in Base32/Base64).CASE: Whether decoding should be case-insensitive (e.g.,truefor Crockford Base32).CODE: A marker type defining the specific encoding scheme (e.g.,Rfc4648,Crockford).
Implementationsยง
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<16, false, PAD, CASE, Rfc4648>
impl<const PAD: bool, const CASE: bool> Base<16, false, PAD, CASE, Rfc4648>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<16, true, PAD, CASE, Rfc4648>
impl<const PAD: bool, const CASE: bool> Base<16, true, PAD, CASE, Rfc4648>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<32, false, PAD, CASE, Rfc4648>
impl<const PAD: bool, const CASE: bool> Base<32, false, PAD, CASE, Rfc4648>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<32, true, PAD, CASE, Rfc4648>
impl<const PAD: bool, const CASE: bool> Base<32, true, PAD, CASE, Rfc4648>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<32, false, PAD, CASE, Crockford>
impl<const PAD: bool, const CASE: bool> Base<32, false, PAD, CASE, Crockford>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<32, true, PAD, CASE, Crockford>
impl<const PAD: bool, const CASE: bool> Base<32, true, PAD, CASE, Crockford>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<32, false, PAD, CASE, Rfc4648Hex>
impl<const PAD: bool, const CASE: bool> Base<32, false, PAD, CASE, Rfc4648Hex>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<32, true, PAD, CASE, Rfc4648Hex>
impl<const PAD: bool, const CASE: bool> Base<32, true, PAD, CASE, Rfc4648Hex>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<64, false, PAD, CASE, Rfc4648>
impl<const PAD: bool, const CASE: bool> Base<64, false, PAD, CASE, Rfc4648>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const PAD: bool, const CASE: bool> Base<64, true, PAD, CASE, Rfc4648>
impl<const PAD: bool, const CASE: bool> Base<64, true, PAD, CASE, Rfc4648>
Sourcepub const fn encoded_len(input_len: usize) -> usize
pub const fn encoded_len(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn encoded_len_padded(input_len: usize) -> usize
pub const fn encoded_len_padded(input_len: usize) -> usize
Returns the required output buffer size for encoding input_len bytes.
Sourcepub const fn decoded_len(input_len: usize) -> usize
pub const fn decoded_len(input_len: usize) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Sourcepub const fn decoded_len_stripped(input: &[u8]) -> usize
pub const fn decoded_len_stripped(input: &[u8]) -> usize
Returns the required output buffer size for decoding input_len Base32 characters.
Strips the padding. Otherwise decoded_len will calculate for the worst case.
Sourcepub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
pub const fn decode_from_slice(input: &[u8], output: &mut [u8]) -> Option<usize> โ
Decodes input into output, returning the number of bytes written.
Uses a LUT when DEC_TABLE = true, otherwise falls back to linear search.
Returns None if it finds an invalid byte.
ยงPanics
Panics if output is too small.
Sourceยงimpl<const RADIX: usize, const LUT: bool, const PAD: bool, const CASE: bool, CODE> Base<RADIX, LUT, PAD, CASE, CODE>
ยงmisc. methods
impl<const RADIX: usize, const LUT: bool, const PAD: bool, const CASE: bool, CODE> Base<RADIX, LUT, PAD, CASE, CODE>
ยงmisc. methods
Sourcepub const fn with_radix<const NEW_RADIX: usize>(
self,
) -> Base<NEW_RADIX, LUT, PAD, CASE, CODE>
pub const fn with_radix<const NEW_RADIX: usize>( self, ) -> Base<NEW_RADIX, LUT, PAD, CASE, CODE>
Change the radix while keeping everything else the same.
Sourcepub const fn with_lut<const NEW_LUT: bool>(
self,
) -> Base<RADIX, NEW_LUT, PAD, CASE, CODE>
pub const fn with_lut<const NEW_LUT: bool>( self, ) -> Base<RADIX, NEW_LUT, PAD, CASE, CODE>
Toggle LUT usage while keeping everything else the same.
Sourcepub const fn with_pad<const NEW_PAD: bool>(
self,
) -> Base<RADIX, LUT, NEW_PAD, CASE, CODE>
pub const fn with_pad<const NEW_PAD: bool>( self, ) -> Base<RADIX, LUT, NEW_PAD, CASE, CODE>
Toggle padding while keeping everything else the same.
Sourcepub const fn with_case<const NEW_CASE: bool>(
self,
) -> Base<RADIX, LUT, PAD, NEW_CASE, CODE>
pub const fn with_case<const NEW_CASE: bool>( self, ) -> Base<RADIX, LUT, PAD, NEW_CASE, CODE>
Change the case sensitivity while keeping everything else the same.
Sourcepub const fn with_encoding<NewCode>(
self,
) -> Base<RADIX, LUT, PAD, CASE, NewCode>
pub const fn with_encoding<NewCode>( self, ) -> Base<RADIX, LUT, PAD, CASE, NewCode>
Change the encoding scheme while keeping everything else the same.