cloudevents/
lib.rs

1//! This crate implements the [CloudEvents](https://cloudevents.io/) Spec for Rust.
2//!
3//! ```
4//! # use std::error::Error;
5//! # fn main() -> Result<(), Box<dyn Error>> {
6//! use cloudevents::{EventBuilder, AttributesReader, EventBuilderV10};
7//! use chrono::{Utc, DateTime};
8//! use url::Url;
9//!
10//! let event = EventBuilderV10::new()
11//!     .id("my_event.my_application")
12//!     .source("http://localhost:8080")
13//!     .ty("example.demo")
14//!     .time(Utc::now())
15//!     .build()?;
16//!
17//! println!("CloudEvent Id: {}", event.id());
18//! match event.time() {
19//!     Some(t) => println!("CloudEvent Time: {}", t),
20//!     None => println!("CloudEvent Time: None")
21//! }
22//! # Ok(())
23//! # }
24//! ```
25//!
26//! This crate includes:
27//!
28//! * The [`Event`] data structure, to represent CloudEvent (version 1.0 and 0.3)
29//! * The [`EventBuilder`] trait and implementations, to create [`Event`] instances
30//! * The implementation of [`serde::Serialize`] and [`serde::Deserialize`] for [`Event`] to serialize/deserialize CloudEvents to/from JSON
31//! * Traits and utilities in [`message`] to implement Protocol Bindings
32//! * Feature-guarded modules for various Protocol Binding implementations, e.g. actix, axum, reqwest, warp, rdkafka
33//!
34//! ## Feature flags
35//!
36//! Cloudevents uses a set of [feature flags] to conditionally compile
37//! only the module associated with the Protocol Binding you need:
38//!
39//! - `actix`: Enables the [`binding::actix`] protocol binding module. This
40//! extends the [`actix_web::HttpRequest`] with a
41//! [`to_event`](binding::actix::HttpRequestExt::to_event) function, the
42//! [`actix_web::HttpResponseBuilder`] with an
43//! [`event`](binding::actix::HttpResponseBuilderExt::event) function,
44//! and implementations for [`actix_web::FromRequest`] and
45//! [`actix_web::Responder`] in order to take advantage of actix-web's
46//! [Extractors] and [Responders]
47//! - `reqwest`: Enables the [`binding::reqwest`] protocol binding module.
48//! - `warp`: Enables the [`binding::warp`] protocol binding module.
49//! - `axum`: Enables the [`binding::axum`] protocol binding module.
50//! - `rdkafka`: Enables the [`binding::rdkafka`] protocol binding module to
51//! seamlessly consume/produce cloudevents within Kafka messages.
52//!
53//! [feature flags]: https://doc.rust-lang.org/cargo/reference/manifest.html#the-features-section
54//! [Extractors]: https://actix.rs/docs/extractors/
55//! [Responders]: https://actix.rs/docs/handlers/
56
57#![doc(html_root_url = "https://docs.rs/cloudevents-sdk/0.8.0")]
58#![deny(rustdoc::broken_intra_doc_links)]
59#![cfg_attr(docsrs, feature(doc_cfg))] // Show feature gate in doc
60
61pub mod binding;
62pub mod event;
63pub mod message;
64
65#[cfg(test)]
66pub mod test;
67
68pub use event::Data;
69pub use event::Event;
70pub use event::{AttributesReader, AttributesWriter};
71pub use event::{EventBuilder, EventBuilderV03, EventBuilderV10};