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