Renamed features (#140)

* Renamed features
Moved all bindings under a binding crate

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Cargo fmt

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Now this should build

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Use the new cache plugin

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Fix

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Fix the build

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Fixed doc links

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>

* Change link

Signed-off-by: Francesco Guardiani <francescoguard@gmail.com>
This commit is contained in:
Francesco Guardiani 2021-07-07 10:47:30 +02:00 committed by GitHub
parent cd98c6705e
commit 589db8e5be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
31 changed files with 165 additions and 133 deletions

View File

@ -32,21 +32,19 @@ jobs:
if: matrix.target == 'x86_64-unknown-linux-musl'
# Caching stuff
- name: Cache cargo registry
uses: actions/cache@v1
- uses: actions/cache@v2
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v1
path: |
~/.cargo/bin/
~/.cargo/registry/index/
~/.cargo/registry/cache/
~/.cargo/git/db/
key: ${{ runner.os }}-cargo-deps-${{ hashFiles('**/Cargo.toml') }}
- uses: actions/cache@v2
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v1
with:
path: target
key: ${{ runner.os }}-cargo-build-target-${{ matrix.toolchain }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
path: |
target/
key: ${{ runner.os }}-cargo-target-${{ matrix.toolchain }}-${{ matrix.target }}-${{ hashFiles('**/Cargo.toml') }}
- uses: actions-rs/toolchain@v1
with:
toolchain: ${{ matrix.toolchain }}
@ -97,7 +95,7 @@ jobs:
with:
command: build
toolchain: ${{ matrix.toolchain }}
args: --target wasm32-unknown-unknown --features cloudevents-reqwest
args: --target wasm32-unknown-unknown --features reqwest
# Build examples
- uses: actions-rs/cargo@v1

View File

@ -17,10 +17,10 @@ categories = ["web-programming", "encoding", "data-structures"]
name = "cloudevents"
[features]
cloudevents-actix = ["actix-web", "async-trait", "lazy_static", "bytes", "futures"]
cloudevents-reqwest = ["reqwest", "async-trait", "lazy_static", "bytes"]
cloudevents-rdkafka = ["rdkafka", "lazy_static", "bytes"]
cloudevents-warp = ["warp", "lazy_static", "bytes", "http", "hyper"]
actix = ["actix-web", "async-trait", "lazy_static", "bytes", "futures"]
reqwest = ["reqwest-lib", "async-trait", "lazy_static", "bytes"]
rdkafka = ["rdkafka-lib", "lazy_static", "bytes", "futures"]
warp = ["warp-lib", "lazy_static", "bytes", "http", "hyper"]
[dependencies]
serde = { version = "^1.0", features = ["derive"] }
@ -34,9 +34,9 @@ bitflags = "^1.2"
# runtime optional deps
actix-web = { version = "^3", default-features = false, optional = true }
reqwest = { version = "^0.11", default-features = false, features = ["rustls-tls"], optional = true }
rdkafka = { version = "^0.25", features = ["cmake-build"], optional = true }
warp = { version = "^0.3", optional = true }
reqwest-lib = { version = "^0.11", default-features = false, features = ["rustls-tls"], optional = true, package = "reqwest" }
rdkafka-lib = { version = "^0.25", features = ["cmake-build"], optional = true, package = "rdkafka" }
warp-lib = { version = "^0.3", optional = true, package = "warp" }
async-trait = { version = "^0.1.33", optional = true }
lazy_static = { version = "1.4.0", optional = true }
bytes = { version = "^1.0", optional = true }

View File

@ -25,10 +25,10 @@ The core modules include definitions for the `Event` and
mechanism to support various Protocol Bindings, each of which is
enabled by a specific [feature flag]:
* `cloudevents-actix`: Integration with [actix](https://actix.rs/).
* `cloudevents-warp`: Integration with [warp](https://github.com/seanmonstar/warp/).
* `cloudevents-reqwest`: Integration with [reqwest](https://github.com/seanmonstar/reqwest).
* `cloudevents-rdkafka`: Integration with [rdkafka](https://fede1024.github.io/rust-rdkafka).
* `actix`: Integration with [actix](https://actix.rs/).
* `warp`: Integration with [warp](https://github.com/seanmonstar/warp/).
* `reqwest`: Integration with [reqwest](https://github.com/seanmonstar/reqwest).
* `rdkafka`: Integration with [rdkafka](https://fede1024.github.io/rust-rdkafka).
This crate is continuously tested to work with GNU libc, WASM and musl
toolchains.
@ -40,7 +40,7 @@ enabling your Protocol Binding of choice:
```toml
[dependencies]
cloudevents-sdk = { version = "0.3.1", features = ["cloudevents-actix"] }
cloudevents-sdk = { version = "0.3.1", features = ["actix"] }
```
Now you can start creating events:

View File

@ -5,12 +5,9 @@ authors = ["Francesco Guardiani <francescoguard@gmail.com>"]
edition = "2018"
[dependencies]
cloudevents-sdk = { path = "../..", features = ["cloudevents-actix"] }
cloudevents-sdk = { path = "../..", features = ["actix"] }
actix-web = "^3"
actix-cors = "^0.5"
lazy_static = "1.4.0"
bytes = "^0.5"
futures = "^0.3"
serde_json = "^1.0"
url = { version = "^2.1" }
env_logger = "0.7.1"

View File

@ -8,7 +8,7 @@ edition = "2018"
[dependencies]
async-trait = "^0.1.33"
cloudevents-sdk = { path = "../..", features = ["cloudevents-rdkafka"] }
cloudevents-sdk = { path = "../..", features = ["rdkafka"] }
lazy_static = "1.4.0"
bytes = "^1.0"
url = { version = "^2.1", features = ["serde"] }

View File

@ -3,7 +3,7 @@ use futures::StreamExt;
use serde_json::json;
use cloudevents::{EventBuilder, EventBuilderV10};
use cloudevents::rdkafka::{FutureRecordExt, MessageExt, MessageRecord};
use cloudevents::binding::rdkafka::{FutureRecordExt, MessageExt, MessageRecord};
use rdkafka::config::{ClientConfig, RDKafkaLogLevel};
use rdkafka::consumer::stream_consumer::StreamConsumer;

View File

@ -11,7 +11,7 @@ crate-type = ["cdylib"]
[dependencies]
reqwest = "^0.11"
cloudevents-sdk = { path = "../..", features = ["cloudevents-reqwest"] }
cloudevents-sdk = { path = "../..", features = ["reqwest"] }
url = { version = "^2.1" }
web-sys = { version = "0.3.39", features = ["Window", "Location"] }
wasm-bindgen-futures = "0.4.12"

View File

@ -1,4 +1,4 @@
use cloudevents::reqwest::RequestBuilderExt;
use cloudevents::binding::reqwest::RequestBuilderExt;
use cloudevents::{EventBuilder, EventBuilderV10};
use wasm_bindgen::prelude::*;

View File

@ -7,6 +7,6 @@ categories = ["web-programming", "encoding"]
license-file = "../LICENSE"
[dependencies]
cloudevents-sdk = { path = "../..", features = ["cloudevents-warp"] }
cloudevents-sdk = { path = "../..", features = ["warp"] }
warp = "^0.3"
tokio = { version = "^1.0", features = ["full"] }

View File

@ -1,4 +1,4 @@
use cloudevents::warp::{filter, reply};
use cloudevents::binding::warp::{filter, reply};
use warp::Filter;
#[tokio::main]

View File

@ -3,7 +3,7 @@
//! To deserialize an HTTP request as CloudEvent:
//!
//! ```
//! use cloudevents::actix::HttpRequestExt;
//! use cloudevents::binding::actix::HttpRequestExt;
//! use actix_web::{HttpRequest, web, post};
//!
//! #[post("/")]
@ -17,7 +17,7 @@
//! To serialize a CloudEvent to an HTTP response:
//!
//! ```
//! use cloudevents::actix::HttpResponseBuilderExt;
//! use cloudevents::binding::actix::HttpResponseBuilderExt;
//! use actix_web::{HttpRequest, web, get, HttpResponse};
//! use cloudevents::{EventBuilderV10, EventBuilder};
//! use serde_json::json;

10
src/binding/mod.rs Normal file
View File

@ -0,0 +1,10 @@
//! Provides protocol binding implementations for [`crate::Event`].
#[cfg(feature = "actix")]
pub mod actix;
#[cfg(feature = "rdkafka")]
pub mod rdkafka;
#[cfg(feature = "reqwest")]
pub mod reqwest;
#[cfg(feature = "warp")]
pub mod warp;

View File

@ -1,3 +1,5 @@
use rdkafka_lib as rdkafka;
use super::headers;
use crate::event::SpecVersion;
use crate::message::{
@ -155,6 +157,8 @@ impl MessageExt for OwnedMessage {
}
mod private {
use rdkafka_lib as rdkafka;
// Sealing the MessageExt
pub trait Sealed {}
impl Sealed for rdkafka::message::OwnedMessage {}
@ -163,8 +167,10 @@ mod private {
#[cfg(test)]
mod tests {
use rdkafka_lib as rdkafka;
use super::*;
use crate::rdkafka::kafka_producer_record::MessageRecord;
use crate::binding::rdkafka::kafka_producer_record::MessageRecord;
use crate::{EventBuilder, EventBuilderV10};
use chrono::Utc;

View File

@ -1,3 +1,5 @@
use rdkafka_lib as rdkafka;
use super::headers;
use crate::event::SpecVersion;
use crate::message::{
@ -140,6 +142,8 @@ impl<'a, K: ToBytes + ?Sized> FutureRecordExt<'a, K> for FutureRecord<'a, K, Vec
}
mod private {
use rdkafka_lib as rdkafka;
// Sealing the FutureRecordExt and BaseRecordExt
pub trait Sealed {}
impl<K: rdkafka::message::ToBytes + ?Sized, V: rdkafka::message::ToBytes> Sealed

View File

@ -4,11 +4,11 @@
//! To produce Cloudevents:
//!
//! ```
//!
//! # use rdkafka_lib as rdkafka;
//! use cloudevents::Event;
//! use rdkafka::producer::{FutureProducer, FutureRecord};
//! use rdkafka::util::Timeout;
//! use cloudevents::rdkafka::{MessageRecord, FutureRecordExt};
//! use cloudevents::binding::rdkafka::{MessageRecord, FutureRecordExt};
//!
//! # async fn produce(producer: &FutureProducer, event: Event) -> Result<(), Box<dyn std::error::Error>> {
//! let message_record = MessageRecord::from_event(event)?;
@ -27,8 +27,9 @@
//! To consume Cloudevents:
//!
//! ```
//! # use rdkafka_lib as rdkafka;
//! use rdkafka::consumer::{StreamConsumer, DefaultConsumerContext, Consumer, CommitMode};
//! use cloudevents::rdkafka::MessageExt;
//! use cloudevents::binding::rdkafka::MessageExt;
//! use futures::StreamExt;
//!
//! # async fn consume(consumer: StreamConsumer<DefaultConsumerContext>) -> Result<(), Box<dyn std::error::Error>> {

View File

@ -1,3 +1,5 @@
use reqwest_lib as reqwest;
use super::headers;
use crate::event::SpecVersion;
use crate::message::{
@ -83,6 +85,8 @@ impl RequestBuilderExt for RequestBuilder {
// Sealing the RequestBuilderExt
mod private {
use reqwest_lib as reqwest;
pub trait Sealed {}
impl Sealed for reqwest::RequestBuilder {}
}
@ -91,6 +95,7 @@ mod private {
mod tests {
use super::*;
use mockito::{mock, Matcher};
use reqwest_lib as reqwest;
use crate::message::StructuredDeserializer;
use crate::{EventBuilder, EventBuilderV10};

View File

@ -1,3 +1,5 @@
use reqwest_lib as reqwest;
use super::headers;
use crate::event::SpecVersion;
use crate::message::{
@ -127,6 +129,8 @@ impl ResponseExt for Response {
// Sealing the ResponseExt
mod private {
use reqwest_lib as reqwest;
pub trait Sealed {}
impl Sealed for reqwest::Response {}
}
@ -135,6 +139,7 @@ mod private {
mod tests {
use super::*;
use mockito::mock;
use reqwest_lib as reqwest;
use crate::{EventBuilder, EventBuilderV10};
use chrono::Utc;

View File

@ -1,3 +1,5 @@
use reqwest_lib as reqwest;
use crate::event::SpecVersion;
use lazy_static::lazy_static;
use reqwest::header::{HeaderName, HeaderValue};

View File

@ -1,7 +1,8 @@
//! This module integrates the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) with [reqwest](https://docs.rs/reqwest/) to easily send and receive CloudEvents.
//!
//! ```
//! use cloudevents::reqwest::{RequestBuilderExt, ResponseExt};
//! # use reqwest_lib as reqwest;
//! use cloudevents::binding::reqwest::{RequestBuilderExt, ResponseExt};
//! use cloudevents::{EventBuilderV10, EventBuilder};
//! use serde_json::json;
//!

View File

@ -1,3 +1,5 @@
use warp_lib as warp;
use super::server_request::request_to_event;
use crate::Event;
@ -16,7 +18,8 @@ impl warp::reject::Reject for EventFilterError {}
/// # Extracts [`crate::Event`] from incoming request
///
/// ```
/// use cloudevents::warp::filter::to_event;
/// # use warp_lib as warp;
/// use cloudevents::binding::warp::filter::to_event;
/// use warp::Filter;
/// use warp::Reply;
///
@ -25,7 +28,7 @@ impl warp::reject::Reject for EventFilterError {}
/// .map(|event| {
/// // do something with the event
/// }
/// );
/// );
/// ```
///
pub fn to_event() -> impl Filter<Extract = (Event,), Error = Rejection> + Copy {
@ -41,6 +44,8 @@ async fn create_event(headers: HeaderMap, body: bytes::Bytes) -> Result<Event, R
#[cfg(test)]
mod tests {
use warp_lib as warp;
use super::to_event;
use warp::test;

View File

@ -1,3 +1,5 @@
use warp_lib as warp;
use crate::event::SpecVersion;
use http::header::HeaderName;
use lazy_static::lazy_static;

71
src/binding/warp/mod.rs Normal file
View File

@ -0,0 +1,71 @@
//! This module integrates the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) with [Warp web service framework](https://docs.rs/warp/)
//! to easily send and receive CloudEvents.
//!
//! To deserialize an HTTP request as CloudEvent
//!
//! To echo events:
//!
//! ```
//! # use warp_lib as warp;
//! use warp::{Filter, Reply};
//! use cloudevents::binding::warp::reply::from_event;
//! use cloudevents::binding::warp::filter::to_event;
//!
//! let routes = warp::any()
//! // extracting event from request
//! .and(to_event())
//! // returning event back
//! .map(|event| from_event(event));
//!
//! warp::serve(routes).run(([127, 0, 0, 1], 3030));
//! ```
//!
//! To create event inside request handlers and send them as responses:
//!
//! ```
//! # use warp_lib as warp;
//! use cloudevents::{Event, EventBuilder, EventBuilderV10};
//! use http::StatusCode;
//! use serde_json::json;
//! use warp::{Filter, Reply};
//! use cloudevents::binding::warp::reply::from_event;
//!
//! let routes = warp::any().map(|| {
//! let event = EventBuilderV10::new()
//! .id("1")
//! .source("url://example_response/")
//! .ty("example.ce")
//! .data(
//! mime::APPLICATION_JSON.to_string(),
//! json!({
//! "name": "John Doe",
//! "age": 43,
//! "phones": [
//! "+44 1234567",
//! "+44 2345678"
//! ]
//! }),
//! )
//! .build();
//!
//! match event {
//! Ok(event) => Ok(from_event(event)),
//! Err(e) => Ok(warp::reply::with_status(
//! e.to_string(),
//! StatusCode::INTERNAL_SERVER_ERROR,
//! )
//! .into_response()),
//! }
//! });
//!
//! warp::serve(routes).run(([127, 0, 0, 1], 3030));
//! ```
#[macro_use]
mod headers;
mod server_request;
mod server_response;
pub mod filter;
pub mod reply;

View File

@ -1,3 +1,5 @@
use warp_lib as warp;
use super::server_response::event_to_response;
use crate::Event;
@ -8,7 +10,8 @@ use warp::reply::Response;
/// # Serializes [`crate::Event`] as a http response
///
/// ```
/// use cloudevents::warp::reply::from_event;
/// # use warp_lib as warp;
/// use cloudevents::binding::warp::reply::from_event;
/// use cloudevents::Event;
/// use warp::Filter;
/// use warp::Reply;
@ -28,7 +31,6 @@ pub fn from_event(event: Event) -> Response {
#[cfg(test)]
mod tests {
use crate::{EventBuilder, EventBuilderV10};
use serde_json::json;

View File

@ -1,3 +1,5 @@
use warp_lib as warp;
use super::headers;
use crate::event::SpecVersion;

View File

@ -36,20 +36,17 @@
//! Cloudevents uses a set of [feature flags] to conditionally compile
//! only the module associated with the Protocol Binding you need:
//!
//! - `cloudevents-actix`: Enables the [actix] module. This
//! - `actix`: Enables the [`binding::actix`] protocol binding module. This
//! extends the [`actix_web::HttpRequest`] with a
//! [`to_event`](actix::HttpRequestExt::to_event) function, the
//! [`to_event`](binding::actix::HttpRequestExt::to_event) function, the
//! [`actix_web::dev::HttpResponseBuilder`] with an
//! [`event`](actix::HttpResponseBuilderExt::event) function,
//! [`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]
//!
//! - `cloudevents-reqwest`: Enables the [reqwest] module.
//!
//! - `cloudevents-warp`: Enables the [warp] module.
//!
//! - `cloudevents-rdkafka`: Enables the [rdkafka] module to
//! - `reqwest`: Enables the [`binding::reqwest`] protocol binding module.
//! - `warp`: Enables the [`binding::warp`] 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
@ -58,15 +55,7 @@
#![deny(broken_intra_doc_links)]
#[cfg(feature = "cloudevents-actix")]
pub mod actix;
#[cfg(feature = "cloudevents-rdkafka")]
pub mod rdkafka;
#[cfg(feature = "cloudevents-reqwest")]
pub mod reqwest;
#[cfg(feature = "cloudevents-warp")]
pub mod warp;
pub mod binding;
pub mod event;
pub mod message;

View File

@ -1,68 +0,0 @@
//! This module integrates the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) with [Warp web service framework](https://docs.rs/warp/)
//! to easily send and receive CloudEvents.
//!
//! To deserialize an HTTP request as CloudEvent
//!
//! To echo events:
//!
//! ```
//! use warp::{Filter, Reply};
//! use cloudevents::warp::reply::from_event;
//! use cloudevents::warp::filter::to_event;
//!
//! let routes = warp::any()
//! // extracting event from request
//! .and(to_event())
//! // returning event back
//! .map(|event| from_event(event));
//!
//! warp::serve(routes).run(([127, 0, 0, 1], 3030));
//! ```
//!
//! To create event inside request handlers and send them as responses:
//!
//! ```
//! use cloudevents::{Event, EventBuilder, EventBuilderV10};
//! use http::StatusCode;
//! use serde_json::json;
//! use warp::{Filter, Reply};
//! use cloudevents::warp::reply::from_event;
//!
//! let routes = warp::any().map(|| {
//! let event = EventBuilderV10::new()
//! .id("1")
//! .source("url://example_response/")
//! .ty("example.ce")
//! .data(
//! mime::APPLICATION_JSON.to_string(),
//! json!({
//! "name": "John Doe",
//! "age": 43,
//! "phones": [
//! "+44 1234567",
//! "+44 2345678"
//! ]
//! }),
//! )
//! .build();
//!
//! match event {
//! Ok(event) => Ok(from_event(event)),
//! Err(e) => Ok(warp::reply::with_status(
//! e.to_string(),
//! StatusCode::INTERNAL_SERVER_ERROR,
//! )
//! .into_response()),
//! }
//! });
//! warp::serve(routes).run(([127, 0, 0, 1], 3030));
//! ```
#[macro_use]
mod headers;
mod server_request;
mod server_response;
pub mod filter;
pub mod reply;