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§async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self>
async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self>
Source§impl<S> FromRequest<S> for Event
Available on crate feature axum only.
impl<S> FromRequest<S> for Event
axum only.Source§impl FromRequest for Event
Available on crate feature actix only.So that an actix-web handler may take an Event parameter
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 axum only.
impl IntoResponse for Event
axum only.Source§fn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
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>
fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self>
impl IntoResponse to add a header. Read moreSource§fn with_content_type<V>(self, content_type: V) -> WithContentType<Self>
fn with_content_type<V>(self, content_type: V) -> WithContentType<Self>
impl IntoResponse to with a new content type. 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 Responder for Event
Available on crate feature actix only.So that an actix-web handler may return an Event
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>>
Available on crate features http-binding or reqwest or axum or poem only.
impl<T> TryFrom<Event> for Request<Option<T>>
http-binding or reqwest or axum or poem only.Source§impl<T> TryFrom<Event> for Request<Option<T>>
Available on crate features http-0-2-binding or actix or warp only.
impl<T> TryFrom<Event> for Request<Option<T>>
http-0-2-binding or actix or warp only.Source§impl<T> TryFrom<Response<T>> for Event
Available on crate features http-binding or reqwest or axum or poem only.
impl<T> TryFrom<Response<T>> for Event
http-binding or reqwest or axum or poem only.Source§impl<T> TryFrom<Response<T>> for Event
Available on crate features http-0-2-binding or actix or warp only.
impl<T> TryFrom<Response<T>> for Event
http-0-2-binding or actix or warp only.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§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.Source§impl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
Source§fn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
Source§fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
tower::Layer to the handler. Read moreSource§fn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service by providing the stateSource§impl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
Source§fn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service and no state.Source§fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService and no state. Read moreSource§fn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
tokio only.MakeService which stores information
about the incoming connection and has no state. Read moreSource§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>.Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
Source§impl<T> ToStringFallible for Twhere
T: Display,
impl<T> ToStringFallible for Twhere
T: Display,
Source§fn try_to_string(&self) -> Result<String, TryReserveError>
fn try_to_string(&self) -> Result<String, TryReserveError>
ToString::to_string, but without panic on OOM.