1 unstable release
0.1.0 | Jan 30, 2025 |
---|
#151 in #unique
133 downloads per month
Used in unique-uuid
9KB
73 lines
This crate provides procedural macros for generating unique UUIDs associated with tags and types. It offers two main functionalities:
unique_tag
: A procedural macro that generates a unique UUID for a given string tagUniqueTypeTag
: A derive macro that automatically generates a unique UUID for a type
The generated UUIDs are persisted in a TOML file (types.toml
by default) to ensure
consistency across multiple compilations and crate boundaries.
Features
- Persistent UUID generation and storage
- Consistent UUID mapping for types and tags
- Thread-safe file handling
- TOML-based storage format
Examples
use unique_uuid_derive::{unique_tag, UniqueTypeTag};
// Using unique_tag macro
let my_tag = unique_tag!("my_custom_tag");
// Using UniqueTypeTag derive macro
#[derive(UniqueTypeTag)]
struct MyStruct;
File Structure
The crate maintains a TOML file with the following structure:
[unique_tags]
"tag_name" = "uuid"
[unique_type_tags]
"type_name" = "uuid"
Implementation Details
- UUIDs are generated using UUID v4 (random)
- File operations are performed with proper error handling
- The system supports both string tags and type tags
Safety
This crate performs file I/O operations during compilation, which may fail if:
- The process lacks file system permissions
- The TOML file becomes corrupted
- Concurrent compilation attempts cause file access conflicts
Dependencies
~0.7–1.3MB
~28K SLoC