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<'a> FromRequest<'a> for Event
Available on crate feature poem only.
impl<'a> FromRequest<'a> for Event
poem only.source§fn from_request<'life0, 'async_trait>(
req: &'a Request,
body: &'life0 mut RequestBody
) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where
Self: 'async_trait,
'a: 'async_trait,
'life0: 'async_trait,
fn from_request<'life0, 'async_trait>( req: &'a Request, body: &'life0 mut RequestBody ) -> Pin<Box<dyn Future<Output = Result<Self>> + Send + 'async_trait>>where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,
source§impl<B> FromRequest<B> for Eventwhere
B: Body + Send,
B::Data: Send,
B::Error: Into<Box<dyn Error + Send + Sync>>,
Available on crate feature axum only.
impl<B> FromRequest<B> for Eventwhere B: Body + Send, B::Data: Send, B::Error: Into<Box<dyn Error + Send + Sync>>,
axum only.§type Rejection = (StatusCode, String)
type Rejection = (StatusCode, String)
source§impl FromRequest for Event
Available on crate feature actix only.
impl FromRequest for Event
actix only.So that an actix-web handler may take an Event parameter
source§impl IntoResponse for Event
Available on crate feature poem only.
impl IntoResponse for Event
poem only.source§fn into_response(self) -> Response
fn into_response(self) -> Response
Response.source§fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self>where
K: TryInto<HeaderName>,
V: TryInto<HeaderValue>,
Self: Sized,
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self>where K: TryInto<HeaderName>, V: TryInto<HeaderValue>, Self: Sized,
impl IntoResponse to add a header. Read moresource§fn with_status(self, status: StatusCode) -> WithStatus<Self>where
Self: Sized,
fn with_status(self, status: StatusCode) -> WithStatus<Self>where Self: Sized,
impl IntoResponse to set a status code. Read moresource§impl IntoResponse for Event
Available on crate feature axum only.
impl IntoResponse for Event
axum only.source§fn into_response(self) -> Response<BoxBody>
fn into_response(self) -> Response<BoxBody>
source§impl PartialEq<Event> for Event
impl PartialEq<Event> for Event
source§impl Responder for Event
Available on crate feature actix only.
impl Responder for Event
actix only.So that an actix-web handler may return an Event
type Body = BoxBody
source§fn respond_to(self, _: &HttpRequest) -> HttpResponse
fn respond_to(self, _: &HttpRequest) -> HttpResponse
HttpResponse.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.source§impl<T> TryFrom<Event> for Request<Option<T>>where
T: TryFrom<Vec<u8>>,
<T as TryFrom<Vec<u8>>>::Error: Debug,
Available on crate features http-binding or actix or warp or reqwest or axum or poem only.
impl<T> TryFrom<Event> for Request<Option<T>>where T: TryFrom<Vec<u8>>, <T as TryFrom<Vec<u8>>>::Error: Debug,
http-binding or actix or warp or reqwest or axum or poem only.source§impl<T> TryFrom<Response<T>> for Eventwhere
T: TryInto<Vec<u8>>,
<T as TryInto<Vec<u8>>>::Error: Debug,
Available on crate features http-binding or actix or warp or reqwest or axum or poem only.
impl<T> TryFrom<Response<T>> for Eventwhere T: TryInto<Vec<u8>>, <T as TryInto<Vec<u8>>>::Error: Debug,
http-binding or actix or warp or reqwest or axum or poem only.impl Eq for Event
impl StructuralEq for Event
impl StructuralPartialEq for Event
Auto Trait Implementations§
impl RefUnwindSafe for Event
impl Send for Event
impl Sync for Event
impl Unpin for Event
impl UnwindSafe for Event
Blanket Implementations§
source§impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoResult<T> for Twhere
T: IntoResponse,
impl<T> IntoResult<T> for Twhere T: IntoResponse,
source§fn into_result(self) -> Result<T, Error>
fn into_result(self) -> Result<T, Error>
poem::Result<T>.