pub struct SimpleUuid { /* private fields */ }Expand description
简单的 UUID v4 实现
Implementations§
Source§impl SimpleUuid
impl SimpleUuid
Sourcepub fn new_v4() -> Self
pub fn new_v4() -> Self
Examples found in repository?
examples/basic_usage.rs (line 106)
102fn demonstrate_simplified_uuid() -> std::result::Result<(), Box<dyn std::error::Error>> {
103 println!("Generating UUIDs:");
104
105 // Generate multiple UUIDs
106 let uuid1 = SimpleUuid::new_v4();
107 let uuid2 = SimpleUuid::new_v4();
108 let uuid3 = SimpleUuid::new_v4();
109
110 println!(" UUID 1: {}", uuid1);
111 println!(" UUID 2: {}", uuid2);
112 println!(" UUID 3: {}", uuid3);
113 println!(" All unique: {}", uuid1 != uuid2 && uuid2 != uuid3 && uuid1 != uuid3);
114
115 println!();
116 println!("ID Generator:");
117 let generator = IdGenerator::new();
118 let id1 = generator.generate();
119 let id2 = generator.generate();
120
121 println!(" ID 1: {}", id1);
122 println!(" ID 2: {}", id2);
123 println!(" ID 3: {}", generator.with_prefix("user_").generate());
124
125 println!();
126 println!("Simple IDs:");
127 let simple_gen = IdGenerator::new().with_simple_id();
128 println!(" Simple ID: {}", simple_gen.generate());
129 println!(" Prefixed: {}", simple_gen.with_prefix("order_").generate());
130
131 Ok(())
132}More examples
examples/postgresql_example.rs (line 199)
190async fn demonstrate_transactions() -> std::result::Result<(), Box<dyn std::error::Error>> {
191 println!("PostgreSQL transactions (BEGIN / COMMIT / ROLLBACK):");
192 let db = Database::postgresql(PG_HOST, PG_PORT, PG_DB, PG_USER, PG_PASS).await?;
193
194 // Commit
195 let mut tx = db.begin_transaction().await?;
196 tx.execute(
197 "INSERT INTO users (id, name, age) VALUES ($1, $2, $3)",
198 &[
199 SimpleUuid::new_v4().to_string().into(),
200 "Dave".into(),
201 40.into(),
202 ],
203 )
204 .await?;
205 tx.execute(
206 "INSERT INTO users (id, name, age) VALUES ($1, $2, $3)",
207 &[
208 SimpleUuid::new_v4().to_string().into(),
209 "Frank".into(),
210 35.into(),
211 ],
212 )
213 .await?;
214 tx.commit().await?;
215 println!(" ✅ Transaction committed (2 users)");
216
217 // Rollback
218 let mut tx = db.begin_transaction().await?;
219 tx.execute(
220 "INSERT INTO users (id, name, age) VALUES ($1, $2, $3)",
221 &[
222 SimpleUuid::new_v4().to_string().into(),
223 "Eve".into(),
224 45.into(),
225 ],
226 )
227 .await?;
228 tx.rollback().await?;
229 println!(" ✅ Transaction rolled back (Eve not saved)");
230
231 let result = db.query("SELECT COUNT(*) AS count FROM users", &[]).await?;
232 println!(" ✅ Final user count: {:?}", result.rows[0].get("count"));
233
234 db.close().await?;
235 Ok(())
236}
237
238fn demonstrate_simplified_uuid() -> std::result::Result<(), Box<dyn std::error::Error>> {
239 println!("Generating UUIDs:");
240
241 // Generate multiple UUIDs
242 let uuid1 = SimpleUuid::new_v4();
243 let uuid2 = SimpleUuid::new_v4();
244 let uuid3 = SimpleUuid::new_v4();
245
246 println!(" UUID 1: {}", uuid1);
247 println!(" UUID 2: {}", uuid2);
248 println!(" UUID 3: {}", uuid3);
249 println!(
250 " All unique: {}",
251 uuid1 != uuid2 && uuid2 != uuid3 && uuid1 != uuid3
252 );
253
254 println!();
255 println!("ID Generator:");
256 let generator = IdGenerator::new();
257 let id1 = generator.generate();
258 let id2 = generator.generate();
259
260 println!(" ID 1: {}", id1);
261 println!(" ID 2: {}", id2);
262 println!(
263 " ID 3: {}",
264 generator.with_prefix("user_").generate()
265 );
266
267 println!();
268 println!("Simple IDs:");
269 let simple_gen = IdGenerator::new().with_simple_id();
270 println!(" Simple ID: {}", simple_gen.generate());
271 println!(
272 " Prefixed: {}",
273 simple_gen.with_prefix("order_").generate()
274 );
275
276 Ok(())
277}pub fn nil() -> Self
pub fn from_bytes(bytes: [u8; 16]) -> Self
pub fn as_bytes(&self) -> &[u8; 16]
Sourcepub fn to_string(&self) -> String
pub fn to_string(&self) -> String
Examples found in repository?
examples/postgresql_example.rs (line 199)
190async fn demonstrate_transactions() -> std::result::Result<(), Box<dyn std::error::Error>> {
191 println!("PostgreSQL transactions (BEGIN / COMMIT / ROLLBACK):");
192 let db = Database::postgresql(PG_HOST, PG_PORT, PG_DB, PG_USER, PG_PASS).await?;
193
194 // Commit
195 let mut tx = db.begin_transaction().await?;
196 tx.execute(
197 "INSERT INTO users (id, name, age) VALUES ($1, $2, $3)",
198 &[
199 SimpleUuid::new_v4().to_string().into(),
200 "Dave".into(),
201 40.into(),
202 ],
203 )
204 .await?;
205 tx.execute(
206 "INSERT INTO users (id, name, age) VALUES ($1, $2, $3)",
207 &[
208 SimpleUuid::new_v4().to_string().into(),
209 "Frank".into(),
210 35.into(),
211 ],
212 )
213 .await?;
214 tx.commit().await?;
215 println!(" ✅ Transaction committed (2 users)");
216
217 // Rollback
218 let mut tx = db.begin_transaction().await?;
219 tx.execute(
220 "INSERT INTO users (id, name, age) VALUES ($1, $2, $3)",
221 &[
222 SimpleUuid::new_v4().to_string().into(),
223 "Eve".into(),
224 45.into(),
225 ],
226 )
227 .await?;
228 tx.rollback().await?;
229 println!(" ✅ Transaction rolled back (Eve not saved)");
230
231 let result = db.query("SELECT COUNT(*) AS count FROM users", &[]).await?;
232 println!(" ✅ Final user count: {:?}", result.rows[0].get("count"));
233
234 db.close().await?;
235 Ok(())
236}pub fn is_nil(&self) -> bool
pub fn version(&self) -> u8
pub fn variant(&self) -> u8
Trait Implementations§
Source§impl Clone for SimpleUuid
impl Clone for SimpleUuid
Source§fn clone(&self) -> SimpleUuid
fn clone(&self) -> SimpleUuid
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreimpl Copy for SimpleUuid
Source§impl Debug for SimpleUuid
impl Debug for SimpleUuid
Source§impl Default for SimpleUuid
impl Default for SimpleUuid
Source§impl<'de> Deserialize<'de> for SimpleUuid
impl<'de> Deserialize<'de> for SimpleUuid
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Display for SimpleUuid
impl Display for SimpleUuid
impl Eq for SimpleUuid
Source§impl FromStr for SimpleUuid
impl FromStr for SimpleUuid
Source§impl Hash for SimpleUuid
impl Hash for SimpleUuid
Source§impl PartialEq for SimpleUuid
impl PartialEq for SimpleUuid
Source§impl Serialize for SimpleUuid
impl Serialize for SimpleUuid
impl StructuralPartialEq for SimpleUuid
Auto Trait Implementations§
impl Freeze for SimpleUuid
impl RefUnwindSafe for SimpleUuid
impl Send for SimpleUuid
impl Sync for SimpleUuid
impl Unpin for SimpleUuid
impl UnsafeUnpin for SimpleUuid
impl UnwindSafe for SimpleUuid
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more