[][src]Struct cloudevents::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::Event;
use cloudevents::event::AttributesReader;

// Create an event using the Default trait
let mut e = Event::default();
e.write_data(
    "application/json",
    serde_json::json!({"hello": "world"})
);

// Print the event id
println!("Event id: {}", e.get_id());

// Get the event data
let data: serde_json::Value = e.try_get_data().unwrap().unwrap();
println!("Event data: {}", data)

Implementations

impl Event[src]

pub fn remove_data(&mut self)[src]

Remove data, dataschema and datacontenttype from this Event

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

Write data into this Event with the specified datacontenttype.

use cloudevents::Event;
use serde_json::json;
use std::convert::Into;

let mut e = Event::default();
e.write_data("application/json", json!({}))

pub fn write_data_with_schema(
    &mut self,
    datacontenttype: impl Into<String>,
    dataschema: impl Into<Url>,
    data: impl Into<Data>
)
[src]

Write data into this Event with the specified datacontenttype and dataschema.

use cloudevents::Event;
use serde_json::json;
use std::convert::Into;
use url::Url;

let mut e = Event::default();
e.write_data_with_schema(
    "application/json",
    Url::parse("http://myapplication.com/schema").unwrap(),
    json!({})
)

pub fn get_data<T: Sized + From<Data>>(&self) -> Option<T>[src]

Get data from this Event

pub fn try_get_data<T: Sized + TryFrom<Data>>(
    &self
) -> Result<Option<T>, T::Error>
[src]

Try to get data from this Event

pub fn into_data<T: Sized + TryFrom<Data>>(self) -> Result<Option<T>, T::Error>[src]

Transform this Event into the content of data

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

Get the extension named extension_name

pub fn get_extensions(&self) -> Vec<(&str, &ExtensionValue)>[src]

Get all the extensions

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 BinarySerializer<Event> 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 PartialEq<Event> for Event[src]

impl Serialize for Event[src]

impl StructuralPartialEq for Event[src]

impl StructuredDeserializer for Event[src]

impl StructuredSerializer<Event> for Event[src]

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

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, 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.

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