Struct cloudevents::event::Event [−][src]
pub struct Event { /* fields omitted */ }
Expand description
Data structure that represents a CloudEvent.
It provides methods to get the attributes through AttributesReader
and write them through AttributesWriter
.
It also provides methods to read and write the event data.
You can build events using super::EventBuilder
use cloudevents::*; use std::convert::TryInto; // Create an event using the Default trait let mut e = Event::default(); e.set_data( "application/json", serde_json::json!({"hello": "world"}) ); // Print the event id println!("Event id: {}", e.id()); // Get the event data let data: Option<Data> = e.data().cloned(); match data { Some(d) => println!("{}", d), None => println!("No event data") }
Implementations
Returns an Iterator
for all the available CloudEvents Context attributes and extensions.
Same as chaining Event::iter_attributes()
and Event::iter_extensions()
Returns an Iterator
for all the available CloudEvents Context attributes, excluding extensions.
This iterator does not contain the data
field.
Get all the extensions
Take (datacontenttype
, dataschema
, data
) from this event, leaving these fields empty
use cloudevents::Event; use serde_json::json; use std::convert::Into; let mut e = Event::default(); e.set_data("application/json", json!({})); let (datacontenttype, dataschema, data) = e.take_data();
Set data
into this Event
with the specified datacontenttype
.
Returns the previous value of datacontenttype
and data
.
use cloudevents::Event; use serde_json::json; use std::convert::Into; let mut e = Event::default(); let (old_datacontenttype, old_data) = e.set_data("application/json", json!({}));
Set data
into this Event
, without checking if there is a datacontenttype
.
Returns the previous value of data
.
use cloudevents::Event; use serde_json::json; use std::convert::Into; let mut e = Event::default(); let old_data = e.set_data_unchecked(json!({}));
Get the extension named extension_name
pub fn set_extension<'name, 'event: 'name>(
&'event mut self,
extension_name: &'name str,
extension_value: impl Into<ExtensionValue>
)
pub fn set_extension<'name, 'event: 'name>(
&'event mut self,
extension_name: &'name str,
extension_value: impl Into<ExtensionValue>
)
Set the extension named extension_name
with extension_value
pub fn remove_extension<'name, 'event: 'name>(
&'event mut self,
extension_name: &'name str
) -> Option<ExtensionValue>
pub fn remove_extension<'name, 'event: 'name>(
&'event mut self,
extension_name: &'name str
) -> Option<ExtensionValue>
Remove the extension named extension_name
Trait Implementations
Set the datacontenttype. Returns the previous value. Read more
Set the dataschema. Returns the previous value. Read more
Deserialize the message to BinarySerializer
.
Convert this Message to Event
.
fn deserialize<D>(
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D
) -> Result<Self, <D as Deserializer<'de>>::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
fn serialize<S>(
&self,
serializer: S
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error> where
S: Serializer,
Serialize this value into the given Serde serializer. Read more
Deserialize the message to StructuredSerializer
.
Convert this Message to Event
.
Auto Trait Implementations
impl RefUnwindSafe for Event
impl UnwindSafe for Event
Blanket Implementations
Mutably borrows from an owned value. Read more