Struct cloudevents::event::Event
source · pub struct Event { /* private fields */ }
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§
source§impl Event
impl Event
sourcepub fn iter(&self) -> impl Iterator<Item = (&str, AttributeValue<'_>)>
pub fn iter(&self) -> impl Iterator<Item = (&str, AttributeValue<'_>)>
Returns an Iterator
for all the available CloudEvents Context attributes and extensions.
Same as chaining Event::iter_attributes()
and Event::iter_extensions()
sourcepub fn iter_attributes(
&self,
) -> impl Iterator<Item = (&str, AttributeValue<'_>)>
pub fn iter_attributes( &self, ) -> impl Iterator<Item = (&str, AttributeValue<'_>)>
Returns an Iterator
for all the available CloudEvents Context attributes, excluding extensions.
This iterator does not contain the data
field.
sourcepub fn iter_extensions(&self) -> impl Iterator<Item = (&str, &ExtensionValue)>
pub fn iter_extensions(&self) -> impl Iterator<Item = (&str, &ExtensionValue)>
Get all the extensions
sourcepub fn take_data(&mut self) -> (Option<String>, Option<Url>, Option<Data>)
pub fn take_data(&mut self) -> (Option<String>, Option<Url>, Option<Data>)
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();
sourcepub fn set_data(
&mut self,
datacontenttype: impl Into<String>,
data: impl Into<Data>,
) -> (Option<String>, Option<Data>)
pub fn set_data( &mut self, datacontenttype: impl Into<String>, data: impl Into<Data>, ) -> (Option<String>, Option<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!({}));
sourcepub fn set_data_unchecked(&mut self, data: impl Into<Data>) -> Option<Data>
pub fn set_data_unchecked(&mut self, data: impl Into<Data>) -> Option<Data>
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!({}));
sourcepub fn extension(&self, extension_name: &str) -> Option<&ExtensionValue>
pub fn extension(&self, extension_name: &str) -> Option<&ExtensionValue>
Get the extension named extension_name
sourcepub 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
sourcepub 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§
source§impl AttributesReader for Event
impl AttributesReader for Event
source§fn source(&self) -> &UriReference
fn source(&self) -> &UriReference
source§fn specversion(&self) -> SpecVersion
fn specversion(&self) -> SpecVersion
source§fn datacontenttype(&self) -> Option<&str>
fn datacontenttype(&self) -> Option<&str>
source§fn dataschema(&self) -> Option<&Url>
fn dataschema(&self) -> Option<&Url>
source§impl AttributesWriter for Event
impl AttributesWriter for Event
source§fn set_source(&mut self, source: impl Into<UriReference>) -> UriReference
fn set_source(&mut self, source: impl Into<UriReference>) -> UriReference
source§fn set_type(&mut self, ty: impl Into<String>) -> String
fn set_type(&mut self, ty: impl Into<String>) -> String
source§fn set_subject(&mut self, subject: Option<impl Into<String>>) -> Option<String>
fn set_subject(&mut self, subject: Option<impl Into<String>>) -> Option<String>
source§fn set_time(
&mut self,
time: Option<impl Into<DateTime<Utc>>>,
) -> Option<DateTime<Utc>>
fn set_time( &mut self, time: Option<impl Into<DateTime<Utc>>>, ) -> Option<DateTime<Utc>>
source§fn set_datacontenttype(
&mut self,
datacontenttype: Option<impl Into<String>>,
) -> Option<String>
fn set_datacontenttype( &mut self, datacontenttype: Option<impl Into<String>>, ) -> Option<String>
source§fn set_dataschema(&mut self, dataschema: Option<impl Into<Url>>) -> Option<Url>
fn set_dataschema(&mut self, dataschema: Option<impl Into<Url>>) -> Option<Url>
source§impl BinaryDeserializer for Event
impl BinaryDeserializer for Event
source§fn deserialize_binary<R: Sized, V: BinarySerializer<R>>(
self,
visitor: V,
) -> Result<R>
fn deserialize_binary<R: Sized, V: BinarySerializer<R>>( self, visitor: V, ) -> Result<R>
BinarySerializer
.source§impl<'de> Deserialize<'de> for Event
impl<'de> Deserialize<'de> for Event
source§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>,
source§impl From<Event> for EventBuilder
impl From<Event> for EventBuilder
source§impl From<Event> for EventBuilder
impl From<Event> for EventBuilder
source§impl Serialize for Event
impl Serialize for Event
source§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,
source§impl StructuredDeserializer for Event
impl StructuredDeserializer for Event
source§fn deserialize_structured<R, V: StructuredSerializer<R>>(
self,
visitor: V,
) -> Result<R>
fn deserialize_structured<R, V: StructuredSerializer<R>>( self, visitor: V, ) -> Result<R>
StructuredSerializer
.impl Eq for Event
impl StructuralPartialEq for Event
Auto Trait Implementations§
impl Freeze for Event
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin 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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)