# Defining Events

An event describes what has happened. Define it as a struct, derive serde's `Serialize` and `Deserialize` together with `Event`, and name the event type with the `event` attribute.

This makes the struct an `Event`:

```rust
#[derive(Serialize, Deserialize, Event)]
#[event(type = "io.eventsourcingdb.library.book-acquired")]
struct BookAcquired {
  title: String,
  author: String,
  isbn: String,
}

#[derive(Serialize, Deserialize, Event)]
#[event(type = "io.eventsourcingdb.library.book-borrowed")]
#[serde(rename_all = "camelCase")]
struct BookBorrowed {
  borrowed_by: String,
  borrowed_until: String,
}

#[derive(Serialize, Deserialize, Event)]
#[event(type = "io.eventsourcingdb.library.book-returned")]
struct BookReturned {}
```

**The struct becomes the event's data, as serde writes it**, so `rename_all` gives the fields of `BookBorrowed` the names `borrowedBy` and `borrowedUntil`, and `BookReturned` is written as `{}`. The subject is taken from the command, and the source from the store. The database checks every event against the JSON schema of its type, which the derive derives from the fields that serde writes, unless the event names a function of its own with `schema_with`, once the schema is registered (see **[Describing Events with Schemas](/docs/architecturekit/rust/describing-events-with-schemas)** and **[Registering Event Schemas](/docs/architecturekit/rust/registering-event-schemas)**).

The event type is a constant of the trait, so `BookAcquired::EVENT_TYPE` is `io.eventsourcingdb.library.book-acquired`. Which events a state evolves by, it lists in an enum of its own, with one variant per event type (see **[Defining State](/docs/architecturekit/rust/defining-state)**).
