[][src]Struct cloudevents::event::Event

pub struct Event { /* fields omitted */ }

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

impl Event[src]

pub fn iter(&self) -> impl Iterator<Item = (&str, AttributeValue<'_>)>[src]

Returns an Iterator for all the available CloudEvents Context attributes and extensions. Same as chaining Event::iter_attributes() and Event::iter_extensions()

pub fn iter_attributes(
    &self
) -> impl Iterator<Item = (&str, AttributeValue<'_>)>
[src]

Returns an Iterator for all the available CloudEvents Context attributes, excluding extensions. This iterator does not contain the data field.

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

Get all the extensions

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

Get data from this Event

pub fn take_data(&mut self) -> (Option<String>, Option<Url>, Option<Data>)[src]

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

pub fn set_data(
    &mut self,
    datacontenttype: impl Into<String>,
    data: impl Into<Data>
) -> (Option<String>, Option<Data>)
[src]

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

pub fn set_data_unchecked(&mut self, data: impl Into<Data>) -> Option<Data>[src]

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

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

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>
)
[src]

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>
[src]

Remove the extension named extension_name

Trait Implementations

impl AttributesReader for Event[src]

impl AttributesWriter for Event[src]

impl BinaryDeserializer for Event[src]

impl Clone for Event[src]

impl Debug for Event[src]

impl Default for Event[src]

impl<'de> Deserialize<'de> for Event[src]

impl Display for Event[src]

impl Eq for Event[src]

impl From<Event> for EventBuilder[src]

impl From<Event> for EventBuilder[src]

impl PartialEq<Event> for Event[src]

impl Serialize for Event[src]

impl StructuralEq for Event[src]

impl StructuralPartialEq for Event[src]

impl StructuredDeserializer for Event[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.