1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/* Copyright © 2025, CosmicMind, Inc. */
//! entid provides an entity id generator and validator for Rust models.
//!
//! This library supports both UUIDs and ULIDs:
//!
//! ## UUID (Universally Unique Identifier)
//! - Industry standard for unique identifiers
//! - Multiple versions (v1, v3, v4, v5) for different use cases
//! - Widely supported across databases and systems
//!
//! ## ULID (Universally Unique Lexicographically Sortable Identifier)
//! - Lexicographically sortable (sorts by creation time)
//! - 128-bit compatibility with UUID
//! - No special characters (URL safe)
//! - Monotonicity option for time-ordered IDs
//! - Shorter string representation (26 characters vs 36 for UUID)
//!
//! Choose the identifier type that best suits your application's needs.
//!
//! ## Basic Usage
//!
//! ```rust
//! use entid::{Identifier, Prefix, UuidEntityId};
//!
//! struct User;
//!
//! impl Prefix for User {
//! fn prefix() -> &'static str {
//! "user"
//! }
//!
//! fn delimiter() -> &'static str {
//! "_"
//! }
//! }
//!
//! // Generate a new ID with the prefix "user_"
//! let user_id = UuidEntityId::<User>::generate();
//! println!("User ID: {}", user_id); // e.g., "user_6ba7b810-9dad-11d1-80b4-00c04fd430c8"
//!
//! // Get just the identifier part without the prefix
//! let id_str = user_id.id_str(); // e.g., "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
//!
//! // Get the identifier directly and access its string representation
//! let identifier = user_id.identifier();
//! let id_str_alt = identifier.as_str(); // Same as id_str()
//! ```
//!
//! ## Flexible Creation Methods
//!
//! ```rust
//! use entid::{Identifier, Prefix, UuidEntityId, Uuid};
//! use std::convert::TryFrom;
//! use std::str::FromStr;
//!
//! struct User;
//! impl Prefix for User {
//! fn prefix() -> &'static str { "user" }
//! }
//!
//! // Using the generate method
//! let user_id1 = UuidEntityId::<User>::generate();
//!
//! // Using the new method with flexible string types
//! let id_str = format!("user_{}", Uuid::new_v4());
//! let user_id2 = UuidEntityId::<User>::new(&id_str).unwrap();
//! let user_id3 = UuidEntityId::<User>::new(id_str.clone()).unwrap();
//!
//! // Using TryFrom trait
//! let user_id4 = UuidEntityId::<User>::try_from(&id_str).unwrap();
//! let user_id5 = UuidEntityId::<User>::try_from(id_str.clone()).unwrap();
//!
//! // Using FromStr trait
//! let user_id6 = id_str.parse::<UuidEntityId<User>>().unwrap();
//!
//! // Using convenience methods
//! let uuid = Uuid::new_v4();
//! let user_id7 = UuidEntityId::<User>::with_uuid(uuid);
//! let user_id8 = UuidEntityId::<User>::new_v4();
//! let user_id9 = UuidEntityId::<User>::new_v5(&Uuid::NAMESPACE_DNS, "example.com");
//!
//! // Using the builder pattern
//! let user_id10 = UuidEntityId::<User>::builder().build();
//! let user_id11 = UuidEntityId::<User>::builder().with_uuid(uuid).build();
//! let user_id12 = UuidEntityId::<User>::builder().with_uuid_v4().build();
//! let user_id13 = UuidEntityId::<User>::builder().with_uuid_v5(&Uuid::NAMESPACE_DNS, "example.com").build();
//! ```
//!
//! ## Using the Derive Macro
//!
//! With the `derive` feature enabled, you can use the derive macro to implement the `Prefix` trait:
//!
//! ```rust
//! # #[cfg(feature = "derive")]
//! use entid::{Identifier, Prefix, UuidEntityId};
//!
//! # #[cfg(feature = "derive")]
//! #[derive(Prefix)]
//! #[entid(prefix = "user", delimiter = "_")]
//! struct User;
//!
//! # #[cfg(feature = "derive")]
//! // The delimiter is optional and defaults to "_"
//! #[derive(Prefix)]
//! #[entid(prefix = "comment")]
//! struct Comment;
//!
//! # #[cfg(feature = "derive")]
//! fn main() {
//! let user_id = UuidEntityId::<User>::generate();
//! println!("User ID: {}", user_id); // e.g., "user_6ba7b810-9dad-11d1-80b4-00c04fd430c8"
//!
//! // Get the full ID string with prefix
//! let full_id = user_id.as_str(); // e.g., "user_6ba7b810-9dad-11d1-80b4-00c04fd430c8"
//!
//! // Get just the identifier part without the prefix
//! let id_str = user_id.id_str(); // e.g., "6ba7b810-9dad-11d1-80b4-00c04fd430c8"
//!
//! // Alternative way to get the identifier string
//! let id_str_alt = user_id.identifier().as_str(); // Same as id_str()
//!
//! let comment_id = UuidEntityId::<Comment>::generate();
//! println!("Comment ID: {}", comment_id); // e.g., "comment_6ba7b810-9dad-11d1-80b4-00c04fd430c8"
//! }
//! # #[cfg(not(feature = "derive"))]
//! # fn main() {}
//! ```
// Re-export key types for users.
pub use ;
pub use ;
pub use ;
// Re-export UUID and ULID types for convenience
pub use Ulid;
pub use Uuid;
// Re-export derive macros when the "derive" feature is enabled
pub use Prefix;