Skip to main content

SimpleUuid

Struct SimpleUuid 

Source
pub struct SimpleUuid { /* private fields */ }
Expand description

简单的 UUID v4 实现

Implementations§

Source§

impl SimpleUuid

Source

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
Hide additional 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}
Source

pub fn nil() -> Self

Source

pub fn from_bytes(bytes: [u8; 16]) -> Self

Source

pub fn as_bytes(&self) -> &[u8; 16]

Source

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}
Source

pub fn is_nil(&self) -> bool

Source

pub fn version(&self) -> u8

Source

pub fn variant(&self) -> u8

Trait Implementations§

Source§

impl Clone for SimpleUuid

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl Copy for SimpleUuid

Source§

impl Debug for SimpleUuid

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SimpleUuid

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SimpleUuid

Source§

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

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for SimpleUuid

Source§

impl FromStr for SimpleUuid

Source§

type Err = String

The associated error which can be returned from parsing.
Source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a string s to return a value of this type. Read more
Source§

impl Hash for SimpleUuid

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for SimpleUuid

Source§

fn eq(&self, other: &SimpleUuid) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for SimpleUuid

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for SimpleUuid

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V