Crate cloudevents
source ·Expand description
This crate implements the CloudEvents Spec for Rust.
use cloudevents::{EventBuilder, AttributesReader, EventBuilderV10};
use chrono::{Utc, DateTime};
use url::Url;
let event = EventBuilderV10::new()
.id("my_event.my_application")
.source("http://localhost:8080")
.ty("example.demo")
.time(Utc::now())
.build()?;
println!("CloudEvent Id: {}", event.id());
match event.time() {
Some(t) => println!("CloudEvent Time: {}", t),
None => println!("CloudEvent Time: None")
}This crate includes:
- The
Eventdata structure, to represent CloudEvent (version 1.0 and 0.3) - The
EventBuildertrait and implementations, to createEventinstances - The implementation of
serde::Serializeandserde::DeserializeforEventto serialize/deserialize CloudEvents to/from JSON - Traits and utilities in
messageto implement Protocol Bindings - Feature-guarded modules for various Protocol Binding implementations, e.g. actix, axum, reqwest, warp, rdkafka
Feature flags
Cloudevents uses a set of feature flags to conditionally compile only the module associated with the Protocol Binding you need:
actix: Enables thebinding::actixprotocol binding module. This extends theactix_web::HttpRequestwith ato_eventfunction, theactix_web::HttpResponseBuilderwith aneventfunction, and implementations foractix_web::FromRequestandactix_web::Responderin order to take advantage of actix-web’s Extractors and Respondersreqwest: Enables thebinding::reqwestprotocol binding module.warp: Enables thebinding::warpprotocol binding module.axum: Enables thebinding::axumprotocol binding module.rdkafka: Enables thebinding::rdkafkaprotocol binding module to seamlessly consume/produce cloudevents within Kafka messages.
Re-exports
pub use event::Event;Modules
Provides protocol binding implementations for
crate::Event.Provides facilities to implement Protocol Bindings.
Macros
Structs
Builder to create a CloudEvent V0.3
Builder to create a CloudEvent V1.0
Enums
Event data attribute representation
Traits
Trait to get CloudEvents Context attributes.
Trait to set CloudEvents Context attributes.
Trait to implement a builder for
Event: