pub struct Event {
pub id: String,
pub event_type: String,
pub source: String,
pub subject: String,
pub content_type: String,
pub version: String,
pub timestamp: DateTime<Utc>,
pub data: Value,
}Expand description
A structured event envelope following CloudEvents conventions.
Fields§
§id: StringUnique event identifier.
event_type: StringThe type of event (e.g. "content.created").
source: StringThe originating service or component.
subject: StringOptional subject the event relates to.
content_type: StringMIME type of the data field.
version: StringSchema version of the event.
timestamp: DateTime<Utc>When the event was created.
data: ValueArbitrary event payload.
Implementations§
Source§impl Event
impl Event
Sourcepub fn new(event_type: impl Into<String>, source: impl Into<String>) -> Self
pub fn new(event_type: impl Into<String>, source: impl Into<String>) -> Self
Create a new event with the given type and source.
Sourcepub fn with_subject(self, subject: impl Into<String>) -> Self
pub fn with_subject(self, subject: impl Into<String>) -> Self
Set the subject.
Sourcepub fn with_data(self, data: impl Serialize) -> AppResult<Self>
pub fn with_data(self, data: impl Serialize) -> AppResult<Self>
Serialize data into the event payload.
Sourcepub fn with_version(self, version: impl Into<String>) -> Self
pub fn with_version(self, version: impl Into<String>) -> Self
Set the schema version.
Sourcepub fn with_content_type(self, content_type: impl Into<String>) -> Self
pub fn with_content_type(self, content_type: impl Into<String>) -> Self
Set the content type.
Sourcepub fn parse_data<T: DeserializeOwned>(&self) -> AppResult<T>
pub fn parse_data<T: DeserializeOwned>(&self) -> AppResult<T>
Parse the data field into a concrete type.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Event
impl<'de> Deserialize<'de> for Event
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for Event
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin for Event
impl UnsafeUnpin for Event
impl UnwindSafe for Event
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more