Event

Struct 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

Source

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()

Source

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.

Source

pub fn iter_extensions(&self) -> impl Iterator<Item = (&str, &ExtensionValue)>

Get all the extensions

Source

pub fn data(&self) -> Option<&Data>

Get data from this Event

Source

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();
Source

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!({}));
Source

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!({}));
Source

pub fn extension(&self, extension_name: &str) -> Option<&ExtensionValue>

Get the extension named extension_name

Source

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

Source

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

Source§

fn id(&self) -> &str

Get the id.
Source§

fn source(&self) -> &UriReference

Get the source.
Source§

fn specversion(&self) -> SpecVersion

Get the specversion.
Source§

fn ty(&self) -> &str

Get the type.
Source§

fn datacontenttype(&self) -> Option<&str>

Source§

fn dataschema(&self) -> Option<&Url>

Get the dataschema.
Source§

fn subject(&self) -> Option<&str>

Get the subject.
Source§

fn time(&self) -> Option<&DateTime<Utc>>

Get the time.
Source§

impl AttributesWriter for Event

Source§

fn set_id(&mut self, id: impl Into<String>) -> String

Set the id. Returns the previous value.
Source§

fn set_source(&mut self, source: impl Into<UriReference>) -> UriReference

Set the source. Returns the previous value.
Source§

fn set_type(&mut self, ty: impl Into<String>) -> String

Set the type. Returns the previous value.
Source§

fn set_subject(&mut self, subject: Option<impl Into<String>>) -> Option<String>

Set the subject. Returns the previous value.
Source§

fn set_time( &mut self, time: Option<impl Into<DateTime<Utc>>>, ) -> Option<DateTime<Utc>>

Set the time. Returns the previous value.
Source§

fn set_datacontenttype( &mut self, datacontenttype: Option<impl Into<String>>, ) -> Option<String>

Set the datacontenttype. Returns the previous value.
Source§

fn set_dataschema(&mut self, dataschema: Option<impl Into<Url>>) -> Option<Url>

Set the dataschema. Returns the previous value.
Source§

impl BinaryDeserializer for Event

Source§

fn deserialize_binary<R: Sized, V: BinarySerializer<R>>( self, visitor: V, ) -> Result<R>

Deserialize the message to BinarySerializer.
Source§

fn into_event(self) -> Result<Event>

Convert this Message to Event.
Source§

impl Clone for Event

Source§

fn clone(&self) -> Event

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Event

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for Event

Source§

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
Source§

impl Display for Event

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl From<Event> for EventBuilder

Source§

fn from(event: Event) -> Self

Converts to this type from the input type.
Source§

impl From<Event> for EventBuilder

Source§

fn from(event: Event) -> Self

Converts to this type from the input type.
Source§

impl<'a> FromRequest<'a> for Event

Available on crate feature poem only.
Source§

async fn from_request(req: &'a Request, body: &mut RequestBody) -> Result<Self>

Extract from request head and body.
Source§

fn from_request_without_body( req: &'a Request, ) -> impl Future<Output = Result<Self, Error>> + Send

Extract from request head. Read more
Source§

impl<S> FromRequest<S> for Event
where Bytes: FromRequest<S>, S: Send + Sync,

Available on crate feature axum only.
Source§

type Rejection = Response<Body>

If the extractor fails it’ll use this “rejection” type. A rejection is a kind of error that can be converted into a response.
Source§

async fn from_request(req: Request, _state: &S) -> Result<Self, Self::Rejection>

Perform the extraction.
Source§

impl FromRequest for Event

Available on crate feature actix only.

So that an actix-web handler may take an Event parameter

Source§

type Error = Error

The associated error which can be returned.
Source§

type Future = Pin<Box<dyn Future<Output = Result<Event, <Event as FromRequest>::Error>>>>

Future that resolves to a Self. Read more
Source§

fn from_request(r: &HttpRequest, p: &mut Payload) -> Self::Future

Create a Self from request parts asynchronously.
Source§

fn extract(req: &HttpRequest) -> Self::Future

Create a Self from request head asynchronously. Read more
Source§

impl IntoResponse for Event

Available on crate feature axum only.
Source§

fn into_response(self) -> Response<Body>

Create a response.
Source§

impl IntoResponse for Event

Available on crate feature poem only.
Source§

fn into_response(self) -> Response

Consume itself and return Response.
Source§

fn with_header<K, V>(self, key: K, value: V) -> WithHeader<Self>
where K: TryInto<HeaderName>, V: TryInto<HeaderValue>, Self: Sized,

Wrap an impl IntoResponse to add a header. Read more
Source§

fn with_content_type<V>(self, content_type: V) -> WithContentType<Self>
where V: TryInto<HeaderValue>, Self: Sized,

Wrap an impl IntoResponse to with a new content type. Read more
Source§

fn with_status(self, status: StatusCode) -> WithStatus<Self>
where Self: Sized,

Wrap an impl IntoResponse to set a status code. Read more
Source§

fn with_body(self, body: impl Into<Body>) -> WithBody<Self>
where Self: Sized,

Wrap an impl IntoResponse to set a body. Read more
Source§

impl PartialEq for Event

Source§

fn eq(&self, other: &Event) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Responder for Event

Available on crate feature actix only.

So that an actix-web handler may return an Event

Source§

type Body = BoxBody

Source§

fn respond_to(self, _: &HttpRequest) -> HttpResponse

Convert self to HttpResponse.
Source§

fn customize(self) -> CustomizeResponder<Self>
where Self: Sized,

Wraps responder to allow alteration of its response. Read more
Source§

impl Serialize for Event

Source§

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
Source§

impl StructuredDeserializer for Event

Source§

fn deserialize_structured<R, V: StructuredSerializer<R>>( self, visitor: V, ) -> Result<R>

Deserialize the message to StructuredSerializer.
Source§

fn into_event(self) -> Result<Event>

Convert this Message to Event.
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 reqwest or axum or poem only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(event: Event) -> Result<Self>

Performs the conversion.
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-0-2-binding or actix or warp only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(event: Event) -> Result<Self>

Performs the conversion.
Source§

impl<T> TryFrom<Response<T>> for Event
where T: TryInto<Vec<u8>>, <T as TryInto<Vec<u8>>>::Error: Debug,

Available on crate features http-binding or reqwest or axum or poem only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(response: Response<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl<T> TryFrom<Response<T>> for Event
where T: TryInto<Vec<u8>>, <T as TryInto<Vec<u8>>>::Error: Debug,

Available on crate features http-0-2-binding or actix or warp only.
Source§

type Error = Error

The type returned in the event of a conversion error.
Source§

fn try_from(response: Response<T>) -> Result<Self, Self::Error>

Performs the conversion.
Source§

impl Eq for Event

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T, S> Handler<IntoResponseHandler, S> for T
where T: IntoResponse + Clone + Send + Sync + 'static,

Source§

type Future = Ready<Response<Body>>

The type of future calling this handler returns.
Source§

fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future

Call the handler with the given request.
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>>,

Apply a tower::Layer to the handler. Read more
Source§

fn with_state(self, state: S) -> HandlerService<Self, T, S>

Convert the handler into a Service by providing the state
Source§

impl<H, T> HandlerWithoutStateExt<T> for H
where H: Handler<T, ()>,

Source§

fn into_service(self) -> HandlerService<H, T, ()>

Convert the handler into a Service and no state.
Source§

fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>

Convert the handler into a MakeService and no state. Read more
Source§

fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>

Available on crate feature tokio only.
Convert the handler into a MakeService which stores information about the incoming connection and has no state. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoResult<T> for T
where T: IntoResponse,

Source§

fn into_result(self) -> Result<T, Error>

Consumes this value returns a poem::Result<T>.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T> ToStringFallible for T
where T: Display,

Source§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,