# Struct envelope::EventsBatch

> A validated `events` batch. Its events are processed in order, exactly as individual events; the batch itself has no stream, sequence or timestamp.

`zaun_community_protocol::envelope::EventsBatch` · Struct

```rust
pub struct EventsBatch { … }
```

A validated `events` batch. Its events are processed in order, exactly as individual
events; the batch itself has no stream, sequence or timestamp.

## Fields

### `v: u16`

Envelope version.

### `community_id: CommunityId`

The community; every element carries the same one.

### `events: Vec<EventEnvelope>`

The events, in order.

## Methods

### `new`

```rust
pub const fn new(community_id: CommunityId, events: Vec<EventEnvelope>) -> Self
```

A batch of `events` for `community_id` at `PROTOCOL_VERSION`.

### `parse`

```rust
pub fn parse(json: &str) -> Result<Self, BatchError>
```

Parses a whole (reassembled) batch envelope. All or nothing: the first bad element
fails the batch.

SPEC: the protocol says each element's `v` and `community_id` MUST equal the batch's; a batch
carrying `stream`, `sequence` or `timestamp` is not rejected (unknown fields are ignored).

# Errors
`BatchError` for the first rule broken.

### `serialize`

```rust
pub fn serialize(&self) -> Result<String, BatchError>
```

The batch envelope as JSON text, after checking the same rules as `Self::parse`.

# Errors
`BatchError` for the first rule an element breaks.

## Trait implementations

`Clone`, `Debug`

[Full rustdoc page](/docs/api/rust/zaun-community-protocol/zaun_community_protocol/envelope/events_batch/struct.EventsBatch.html)
