[][src]Struct cloudevents::Event

pub struct Event {
    pub attributes: Attributes,
    pub data: Option<Data>,
}

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

use cloudevents::Event;
use cloudevents::event::AttributesReader;

// Create an event using the Default trait
let mut e = Event::default();
e.write_data(
    "application/json",
    None,
    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)

Fields

attributes: Attributesdata: Option<Data>

Methods

impl Event[src]

pub fn remove_data(&mut self)[src]

pub fn write_data<S: Into<String>, D: Into<Data>>(
    &mut self,
    content_type: S,
    schema: Option<S>,
    value: D
)
[src]

Write data into the Event. You must provide a content_type and you can optionally provide a schema.

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

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

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

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

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

Trait Implementations

impl AttributesReader for Event[src]

impl AttributesWriter for Event[src]

impl Default 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> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[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.

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