Skip to content

Commit 1902a4e

Browse files
committed
fix: resolve user_service compilation errors in deterministic UUID generation
Fixed compilation issues after eliminating wit-bindgen-rt version conflicts: 1. Removed conflicting Guest trait import that shadowed glob re-export 2. Fixed UUID Builder move semantics by using direct byte manipulation 3. Simplified UUID generation to use Uuid::from_bytes() with manual bit setting 4. Set proper UUID v4 version bits (0100) and RFC4122 variant bits (10) The deterministic UUID generation now: - Uses timestamp + counter for uniqueness without getrandom dependency - Properly formats UUIDs with correct version and variant bits - Avoids all Rust ownership/borrowing issues with Builder pattern - Maintains compatibility with existing UUID::to_string() usage Next: Address any remaining WIT binding export issues.
1 parent 3cf5734 commit 1902a4e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

examples/cpp_component/multi_component_system/components/user_service.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
use serde::{Deserialize, Serialize};
22
use std::collections::HashMap;
3-
use uuid::{Builder, Uuid, Variant, Version};
4-
5-
// Use the generated bindings from rust_wasm_component_bindgen
6-
use user_service_bindings::exports::user_service::Guest;
3+
use uuid::Uuid;
74

85
// Re-export the generated WIT types
96
pub use user_service_bindings::exports::user_service::*;
@@ -32,11 +29,12 @@ fn generate_deterministic_uuid() -> Uuid {
3229
bytes[8..16].copy_from_slice(&counter.to_be_bytes());
3330

3431
// Create UUID v4-style with proper version and variant bits
35-
let mut builder = Builder::from_random_bytes(bytes);
36-
builder
37-
.set_variant(Variant::RFC4122)
38-
.set_version(Version::Random)
39-
.into_uuid()
32+
// Set version 4 bits: set bits 12-15 of the time-high-and-version field to 0100
33+
bytes[6] = (bytes[6] & 0x0F) | 0x40;
34+
// Set variant bits: set bits 6-7 of the clock-seq-hi-and-reserved to 10
35+
bytes[8] = (bytes[8] & 0x3F) | 0x80;
36+
37+
Uuid::from_bytes(bytes)
4038
}
4139

4240
/// Rust User Service Component

0 commit comments

Comments
 (0)