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

pub struct Event { /* fields omitted */ }
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

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

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

Get all the extensions

Get data from this Event

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

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

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

Get the extension named extension_name

Set the extension named extension_name with extension_value

Remove the extension named extension_name

Trait Implementations

Get the id.

Get the source.

Get the specversion.

Get the type.

Get the datacontenttype.

Get the dataschema.

Get the subject.

Get the time.

Set the id. Returns the previous value. Read more

Set the source. Returns the previous value. Read more

Set the type. Returns the previous value. Read more

Set the subject. Returns the previous value. Read more

Set the time. Returns the previous value. Read more

Set the datacontenttype. Returns the previous value. Read more

Set the dataschema. Returns the previous value. Read more

Deserialize the message to BinarySerializer.

Convert this Message to Event.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

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

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Serialize this value into the given Serde serializer. Read more

Deserialize the message to StructuredSerializer.

Convert this Message to Event.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.