RustEurope 2026 in Paris brought together the European Rust community across two days of talks on systems programming, web services, and embedded Rust. UUID v7 featured in sessions on API service design, database integration, and binary protocol implementation. The consensus from speakers mirrored RustConf 2026 in Seattle: UUID v7 via the uuid crate is the recommended default for new Rust services that write to relational databases, replacing both random UUID v4 and bespoke timestamp+random schemes.

Event details

ConferenceRustEurope 2026
DateMay 28–29, 2026
LocationParis, France
FocusUUID v7 in Rust — uuid crate, SQLx, Axum, Actix-web, binary serialisation

Session: uuid crate v7 API and monotonic ClockSequence

The foundational session covered the two UUID v7 generation approaches available in Rust:

// Cargo.toml
// uuid  = { version = "1", features = ["v7", "serde"] }
// uuid7 = "0.7"

// ─── Option A: uuid crate with NoContext (simplest) ───────────────────────
use uuid::{Uuid, Timestamp, NoContext};
use std::time::{SystemTime, UNIX_EPOCH};

pub fn new_uuid_v7() -> Uuid {
    let d  = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
    let ts = Timestamp::from_unix(NoContext, d.as_secs(), d.subsec_nanos());
    Uuid::new_v7(ts)
}

// ─── Option B: uuid crate with atomic monotonic counter ───────────────────
use uuid::ClockSequence;
use std::sync::atomic::{AtomicU16, Ordering};

struct MonotonicCounter(AtomicU16);

impl ClockSequence for MonotonicCounter {
    type Output = u16;
    fn generate_sequence(&self, _secs: u64, _nanos: u32) -> Self::Output {
        self.0.fetch_add(1, Ordering::Relaxed)
    }
    fn usable_bits() -> usize { 12 }
}

static COUNTER: MonotonicCounter = MonotonicCounter(AtomicU16::new(0));

pub fn new_uuid_v7_monotonic() -> Uuid {
    let d  = SystemTime::now().duration_since(UNIX_EPOCH).unwrap();
    let ts = Timestamp::from_unix(&COUNTER, d.as_secs(), d.subsec_nanos());
    Uuid::new_v7(ts)
}

// ─── Option C: uuid7 crate (simplest API) ─────────────────────────────────
// let id = uuid7::uuid7();

The monotonic counter approach — Option B — guarantees that two UUIDs generated in the same millisecond sort in generation order, which is important for database primary key monotonicity. See Monotonic UUID.

Session: Axum web service with UUID v7 primary keys

// src/handlers/orders.rs
use axum::{
    extract::{Path, State},
    http::StatusCode,
    response::Json,
    routing::{get, post},
    Router,
};
use serde::{Deserialize, Serialize};
use sqlx::PgPool;
use uuid::Uuid;

#[derive(Debug, Serialize, sqlx::FromRow)]
pub struct Order {
    pub id:          Uuid,
    pub customer_id: Uuid,
    pub total_cents: i64,
    pub currency:    String,
    pub status:      String,
}

#[derive(Debug, Deserialize)]
pub struct CreateOrderRequest {
    pub customer_id: Uuid,
    pub total_cents: i64,
    pub currency:    String,
}

pub async fn create_order(
    State(pool): State<PgPool>,
    Json(req):   Json<CreateOrderRequest>,
) -> Result<(StatusCode, Json<Order>), StatusCode> {
    let id    = new_uuid_v7();
    let order = sqlx::query_as::<_, Order>(
        "INSERT INTO orders (id, customer_id, total_cents, currency, status)
         VALUES ($1, $2, $3, $4, 'pending')
         RETURNING *"
    )
    .bind(id)
    .bind(req.customer_id)
    .bind(req.total_cents)
    .bind(&req.currency)
    .fetch_one(&pool)
    .await
    .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?;

    Ok((StatusCode::CREATED, Json(order)))
}

pub async fn get_order(
    State(pool): State<PgPool>,
    Path(id):    Path<Uuid>,  // Axum parses UUID from path automatically
) -> Result<Json<Order>, StatusCode> {
    sqlx::query_as::<_, Order>("SELECT * FROM orders WHERE id = $1")
        .bind(id)
        .fetch_optional(&pool)
        .await
        .map_err(|_| StatusCode::INTERNAL_SERVER_ERROR)?
        .map(Json)
        .ok_or(StatusCode::NOT_FOUND)
}

pub fn router(pool: PgPool) -> Router {
    Router::new()
        .route("/orders",      post(create_order))
        .route("/orders/:id",  get(get_order))
        .with_state(pool)
}

SQLx maps Uuid directly to PostgreSQL’s uuid column — no to_string() or parse() is needed. See UUID in Databases for the PostgreSQL schema.

Session: SQLx cursor pagination with UUID v7

UUID v7’s time-ordered primary keys enable efficient cursor-based pagination without an OFFSET clause:

// Cursor pagination — UUID v7 as cursor value
pub async fn list_orders_page(
    pool:   &PgPool,
    cursor: Option<Uuid>,
    limit:  i64,
) -> Result<Vec<Order>, sqlx::Error> {
    match cursor {
        None => {
            sqlx::query_as::<_, Order>(
                "SELECT * FROM orders ORDER BY id LIMIT $1"
            )
            .bind(limit)
            .fetch_all(pool)
            .await
        }
        Some(after_id) => {
            sqlx::query_as::<_, Order>(
                "SELECT * FROM orders WHERE id > $1 ORDER BY id LIMIT $2"
            )
            .bind(after_id)
            .bind(limit)
            .fetch_all(pool)
            .await
        }
    }
}

The WHERE id > cursor clause uses the primary key B-tree index for an O(log n) seek — OFFSET pagination degrades to O(n) as offset grows. See UUID in Databases.

Session: Binary serialisation for high-throughput protocols

// Zero-copy UUID v7 in binary protocols (e.g. custom TCP frame, MessagePack)
use uuid::Uuid;

/// Serialise UUID v7 to 16-byte big-endian buffer — zero allocation
pub fn uuid_to_bytes(id: Uuid) -> [u8; 16] {
    *id.as_bytes()  // uuid crate stores bytes in big-endian order
}

/// Parse UUID v7 from 16-byte buffer — zero allocation
pub fn uuid_from_bytes(buf: &[u8; 16]) -> Option<Uuid> {
    let id = Uuid::from_bytes(*buf);
    if id.get_version_num() == 7 { Some(id) } else { None }
}

/// Extract Unix millisecond timestamp from UUID v7 bytes
pub fn extract_timestamp_ms(id: &Uuid) -> u64 {
    let b = id.as_bytes();
    // Top 48 bits = Unix milliseconds (big-endian)
    u64::from_be_bytes([0, 0, b[0], b[1], b[2], b[3], b[4], b[5]])
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn roundtrip_binary() {
        let id    = new_uuid_v7();
        let bytes = uuid_to_bytes(id);
        let back  = uuid_from_bytes(&bytes).expect("valid v7");
        assert_eq!(id, back);
    }

    #[test]
    fn timestamp_within_bounds() {
        use std::time::{SystemTime, UNIX_EPOCH};
        let before = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64;
        let id     = new_uuid_v7();
        let after  = SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_millis() as u64;
        let ts     = extract_timestamp_ms(&id);
        assert!(ts >= before && ts <= after, "timestamp out of bounds: {ts}");
    }
}

Sessions noted that 16-byte binary representation is 2.25× more compact than the 36-character hyphenated string — important for high-frequency event streams and binary wire protocols. See UUID Bit Fields.

Attendee tips

  1. Use uuid7 crate for simplicity — uuid7::uuid7() is one line; reach for uuid crate’s ClockSequence only when you need strict sub-millisecond ordering.
  2. Enable the serde feature — uuid = { version = "1", features = ["v7", "serde"] } makes Uuid automatically Serialize/Deserialize for Axum JSON handlers.
  3. SQLx feature flag — sqlx = { features = ["uuid", "postgres"] } maps Uuid to PostgreSQL uuid with no manual conversion.
  4. Path<Uuid> in Axum — Axum parses UUID v7 strings from URL path segments automatically; no manual parse() required.
  5. Binary is 16 bytes — use id.as_bytes() for binary protocols; id.to_string() only when human-readable output is required.

Further reading

External references

Frequently asked questions

What is the difference between the uuid crate and the uuid7 crate in Rust?

The uuid crate (the canonical crate from the UUID project) requires you to implement or provide a ClockSequence and call Uuid::new_v7(timestamp) explicitly. The uuid7 crate provides a simpler one-call API — uuid7::uuid7() — and handles monotonic sequencing internally. For production services, uuid7 is lower-friction; for full control over clock sequencing (e.g. custom monotonic counters for sub-millisecond ordering), use the uuid crate directly with a custom ClockSequence implementation. See UUID in Rust.

How do I store UUID v7 as bytes in PostgreSQL from Rust using SQLx?

SQLx maps Rust's Uuid type to PostgreSQL's uuid column type when the uuid feature is enabled: add sqlx = { version = "0.8", features = ["uuid", "postgres", "runtime-tokio"] } to Cargo.toml. PostgreSQL stores the uuid type as 16 bytes internally — SQLx handles the binary serialisation transparently. Use query_as! with a struct containing a Uuid field and SQLx will bind and decode it correctly. See UUID in Databases.

Does Rust's uuid crate guarantee that UUID v7 values are sortable as strings?

Yes — UUID v7 values generated by the uuid crate sort lexicographically (as standard hyphenated UUID strings) in the same order as their generation timestamps, because the 48-bit Unix millisecond timestamp occupies the most-significant bytes and the hyphen-separated groups preserve byte order. String comparison of two UUID v7 values gives the same order as a u128 integer comparison of their raw bytes. See Time Precision.