# rok-ids

Collision-resistant ID generation for Rust. Provides CUID2, ULID, UUID v7, NanoID,
and Snowflake as newtype wrappers with `serde` and `sqlx` support.

## Installation

```toml
[dependencies]
rok-ids = { version = "0.1" }
```

## Quick Start

```rust
use rok_ids::{Cuid2, Ulid, UuidV7, NanoId, Snowflake};

let id = Cuid2::new();       // "clh3ov3o40000qzrm4h0gkjba"
let id = Ulid::new();        // "01H2XCEJHE1MREEW0GXKNJ7SQ"
let id = UuidV7::new();      // "018924f0-d2b7-7000-9e84-6f2e3a2a3d00"
let id = NanoId::new();      // "V1StGXR8_Z5jdHi6B-myT"
let id = Snowflake::new(1);  // 7305763804012543000
```

## Serde

All ID types serialize as strings (or i64 for Snowflake).

```rust
#[derive(Serialize, Deserialize)]
pub struct User {
    pub id: Cuid2,
    pub email: String,
}
```

## SQLx

All ID types implement `sqlx::Type`, `Encode`, and `Decode` for PostgreSQL.

```rust
#[derive(sqlx::FromRow)]
pub struct User {
    pub id: Cuid2,
    pub email: String,
}
```

## Which ID to Use?

| ID | Sortable | Length | Use Case |
|---|---|---|---|
| CUID2 | ✗ | 24 chars | Default — collision-resistant, no external deps |
| ULID | ✅ | 26 chars | Time-sortable, Cassandra-like ordering |
| UUID v7 | ✅ | 36 chars | Standard UUID format, time-sortable |
| NanoID | ✗ | 21 chars | Compact, URL-safe |
| Snowflake | ✅ | i64 | Distributed, requires machine ID |
