Generating v0.1.0
GenerateNanoId
pub func GenerateNanoId(into: var char8[..]) -> ! EntropyError
pub func GenerateNanoId(
into: var char8[..],
alphabet: char8[..]
) -> ! NanoIdError
Fills the whole of into with an identifier from the default alphabet, using the operating system's generator.
The identifier is as long as into; NanoIdLength characters is the standard length. Each character is one
random byte, so a twenty-one-character identifier costs twenty-one bytes of entropy. Reports what the system
reported when it could not supply random bytes, leaving into zeroized. An empty into succeeds and requests
nothing.
| Overload | Summary |
|---|---|
pub func GenerateNanoId(into: var char8[..]) -> ! EntropyError | Fills the whole of into with an identifier from the default alphabet, using the operating system's generator. |
pub func GenerateNanoId(into: var char8[..], alphabet: char8[..]) -> ! NanoIdError | Fills the whole of into with an identifier drawn from alphabet, using the operating system's generator. |
Parameters
| Name | Type | Description |
|---|---|---|
into | var char8[..] | the destination, filled completely |
alphabet | char8[..] | between two and 256 distinct ASCII characters |
Returns: success when every character was written
GenerateNanoIdFrom
pub func GenerateNanoIdFrom(
source: &var EntropySource,
into: var char8[..],
alphabet: char8[..]
) -> ! NanoIdError
Fills the whole of into with an identifier drawn from alphabet, using random bytes from source.
The seam for a test, or for a caller with its own generator: the identifier is exactly as unpredictable as the
bytes source supplies, so a deterministic source gives deterministic identifiers. Reports an alphabet failure
from ValidateAlphabet before using source, leaving into untouched, and Entropy with what source
reported, leaving into zeroized.
Parameters
| Name | Type | Description |
|---|---|---|
source | &var EntropySource | where the random bytes come from |
into | var char8[..] | the destination, filled completely |
alphabet | char8[..] | between two and 256 distinct ASCII characters |
Returns: success when every character was written