events: Add simple custom state event example

This commit is contained in:
stoically 2022-02-20 12:34:52 +01:00 committed by GitHub
parent 713f20c852
commit 1db909fbc7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -31,9 +31,25 @@
//! //!
//! # Extending Ruma with custom events //! # Extending Ruma with custom events
//! //!
//! For our example we will create a reaction message event. This can be used with ruma-events //! For our examples we will start with a simple custom state event. `ruma_event`
//! structs, for this event we will use a `SyncMessageEvent` struct but any `MessageEvent` struct //! specifies the state event's `type` and it's [`kind`](crate::EventKind).
//! would work. //!
//! ```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 //! ```rust
//! use ruma_events::{macros::EventContent, SyncMessageEvent}; //! use ruma_events::{macros::EventContent, SyncMessageEvent};