Skip to main content

packed_nanoid_type

Macro packed_nanoid_type 

Source
macro_rules! packed_nanoid_type {
    ($n:expr, $alphabet:ty) => { ... };
}
Expand description

Create a PackedNanoid type with automatic byte size computation.

This macro computes the required byte size B based on the number of characters N and the alphabet’s PACK_BITS using the formula: ceil(N * PACK_BITS / 8).

§Example

use nid::{alphabet::Base64UrlAlphabet, packed_nanoid_type};

// Creates type PackedNanoid<21, Base64UrlAlphabet, 16>
// (21 * 6 bits = 126 bits = 16 bytes)
type PackedId = packed_nanoid_type!(21, Base64UrlAlphabet);