# Events Store (/sdks/rust/reference/events-store)



## EventStore [#eventstore]

Outbound persistent event message. Unlike `Event`, store messages are persisted and can be replayed.

| Field       | Type                      | Description                                    |
| ----------- | ------------------------- | ---------------------------------------------- |
| `id`        | `String`                  | Message ID (auto-generated UUID v4 when empty) |
| `channel`   | `String`                  | Target channel name (required)                 |
| `metadata`  | `String`                  | Optional UTF-8 metadata                        |
| `body`      | `Vec<u8>`                 | Message payload bytes                          |
| `client_id` | `String`                  | Sender identity override                       |
| `tags`      | `HashMap<String, String>` | Arbitrary key-value pairs                      |

### Builder [#builder]

```rust title="main.rs"
let event = EventStore::builder()
    .channel("orders.created")
    .body(b"order-data".to_vec())
    .add_tag("priority", "high")
    .build();
```

## EventStoreResult [#eventstoreresult]

Returned by `send_event_store`.

| Field   | Type     | Description                                 |
| ------- | -------- | ------------------------------------------- |
| `id`    | `String` | Server-assigned event identifier            |
| `sent`  | `bool`   | Whether the server persisted the event      |
| `error` | `String` | Server error message when `sent` is `false` |

## EventStoreReceive [#eventstorereceive]

Received from a subscription callback.

| Field       | Type                      | Description                         |
| ----------- | ------------------------- | ----------------------------------- |
| `id`        | `String`                  | Server-assigned event identifier    |
| `sequence`  | `u64`                     | Monotonic sequence number           |
| `timestamp` | `i64`                     | Server timestamp (Unix nanoseconds) |
| `channel`   | `String`                  | Channel the event was published to  |
| `metadata`  | `String`                  | Publisher metadata                  |
| `body`      | `Vec<u8>`                 | Message payload                     |
| `tags`      | `HashMap<String, String>` | Publisher-attached tags             |

## EventsStoreSubscription [#eventsstoresubscription]

Specifies where a subscription should begin reading.

| Variant                      | Description                                             |
| ---------------------------- | ------------------------------------------------------- |
| `StartNewOnly`               | Only events published after subscription                |
| `StartFromFirst`             | Replay from the first stored event                      |
| `StartFromLast`              | Start from the most recent event                        |
| `StartAtSequence(u64)`       | Start at a specific sequence number                     |
| `StartAtTime(SystemTime)`    | Start at a specific wall-clock time                     |
| `StartAtTimeDelta(Duration)` | Start from `now - delta` (server interprets in seconds) |

## Client Methods [#client-methods]

### send\_event\_store [#send_event_store]

```rust title="main.rs"
let result = client.send_event_store(event).await?;
println!("Stored event ID: {}", result.id);
```

### subscribe\_to\_events\_store [#subscribe_to_events_store]

```rust title="main.rs"
let sub = client.subscribe_to_events_store(
    "orders.created",
    "",
    EventsStoreSubscription::StartFromFirst,
    |event| Box::pin(async move {
        println!("Seq {}: {}", event.sequence, String::from_utf8_lossy(&event.body));
    }),
    None,
).await?;
```

### send\_event\_store\_stream [#send_event_store_stream]

Opens a bidirectional stream. Returns an `EventStoreStreamHandle`.

```rust title="main.rs"
let mut handle = client.send_event_store_stream().await?;
handle.send(event).await?;
handle.close();
```
