compiled-uuid
Anywhere you're building Uuids from a string literal, you should use uuid.
Motivation
If you want to use a fixed Uuid throughout your program and avoid parsing it multiple times, often you might use lazy_static to cache the Uuid after parsing the first time:
lazy_static!
However, this method introduces overhead through parsing and unwrapping at runtime.
uuid, on the other hand, provides a zero-cost runtime solution:
const MY_UUID: Uuid = uuid!;
Usage
compiled_uuid exposes one macro called uuid, which parses Uuids at compile time. On success, it resolves to Uuid::from_bytes, which cannot fail and has zero runtime cost.
When you write this:
let id: Uuid = uuid!;
It expands to this:
let id: Uuid = from_bytes;
If the UUID cannot be parsed successfully:
let id: Uuid = uuid!;
Then a compilation error is raised:
error: invalid character: expected an optional prefix of `urn:uuid:` followed by 0123456789abcdefABCDEF-, found Z at 9
|
| let id: Uuid = uuid!("F9168C5E-ZEB2-4FAA-B6BF-329BF39FA1E4");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
License
compiled-uuid is open-source software, distributed under the MIT license.