From 1db909fbc7c74013768672a17026b86f0fd0975d Mon Sep 17 00:00:00 2001 From: stoically <29637501+stoically@users.noreply.github.com> Date: Sun, 20 Feb 2022 12:34:52 +0100 Subject: [PATCH] events: Add simple custom state event example --- crates/ruma-events/src/lib.rs | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/crates/ruma-events/src/lib.rs b/crates/ruma-events/src/lib.rs index 0f2287ea..247aa686 100644 --- a/crates/ruma-events/src/lib.rs +++ b/crates/ruma-events/src/lib.rs @@ -31,9 +31,25 @@ //! //! # Extending Ruma with custom events //! -//! For our example we will create a reaction message event. This can be used with ruma-events -//! structs, for this event we will use a `SyncMessageEvent` struct but any `MessageEvent` struct -//! would work. +//! For our examples we will start with a simple custom state event. `ruma_event` +//! specifies the state event's `type` and it's [`kind`](crate::EventKind). +//! +//! ```rust +//! use ruma_events::macros::EventContent; +//! use serde::{Deserialize, Serialize}; +//! +//! #[derive(Clone, Debug, Deserialize, Serialize, EventContent)] +//! #[ruma_event(type = "org.example.event", kind = State)] +//! pub struct ExampleContent { +//! field: String, +//! } +//! ``` +//! +//! This can be used with ruma-events structs, such as passing it into +//! `ruma::api::client::state::send_state_event`'s `Request`. +//! +//! As a more advanced example we create a reaction message event. For this event we will use a +//! `SyncMessageEvent` struct but any `MessageEvent` struct would work. //! //! ```rust //! use ruma_events::{macros::EventContent, SyncMessageEvent};