Skip to content

Commit 713dd73

Browse files
Reorganized symbol exports for 0.1 release (cloudevents#45)
* Reorganized exports (removed wrong exporting of whole spec_version package) Signed-off-by: Francesco Guardiani <[email protected]> * Added documentation for exported methods Reworked README.md Signed-off-by: Francesco Guardiani <[email protected]> * cargo fix && cargo fmt Signed-off-by: Francesco Guardiani <[email protected]> * Added doc about tested toolchains Signed-off-by: Francesco Guardiani <[email protected]>
1 parent 594e0a5 commit 713dd73

23 files changed

+127
-24
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ you need to install the Rust tooling using [rustup](https://rustup.rs/).
2727
To build the project:
2828

2929
```sh
30-
cargo build --all-features
30+
cargo build --all-features --all
3131
```
3232

3333
To run all tests:
3434

3535
```sh
36-
cargo test --all-features
36+
cargo test --all-features --all
3737
```
3838

3939
To build and open the documentation:
@@ -42,12 +42,14 @@ To build and open the documentation:
4242
cargo doc --lib --open
4343
```
4444

45-
To run the code formatter:
45+
Before performing the PR, once you have committed all changes, run:
4646

4747
```sh
48-
cargo fmt
48+
cargo fix --all && cargo fmt --all
4949
```
5050

51+
And commit the changed files. These commands will reorganize imports and format the code.
52+
5153
## Suggesting a change
5254

5355
To suggest a change to this repository, submit a

README.md

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# CloudEvents SDK Rust
1+
# CloudEvents SDK Rust [![Crates badge]][crates.io] [![Docs badge]][docs.rs]
22

3-
Work in progress SDK for [CloudEvents](https://github.com/cloudevents/spec)
3+
Work in progress SDK for [CloudEvents](https://github.com/cloudevents/spec).
4+
5+
Note: All APIs are considered unstable.
46

57
## Spec support
68

@@ -18,9 +20,35 @@ Work in progress SDK for [CloudEvents](https://github.com/cloudevents/spec)
1820

1921
## Modules
2022

21-
* `cloudevents-sdk`: Provides Event data structure, JSON Event format implementation
22-
* `cloudevents-sdk-actix-web`: Integration with [Actix Web](https://github.com/actix/actix-web)
23-
* `cloudevents-sdk-reqwest`: Integration with [reqwest](https://github.com/seanmonstar/reqwest)
23+
* `cloudevents-sdk`: Provides Event data structure, JSON Event format implementation. This module is tested to work with GNU libc, WASM and musl toolchains.
24+
* `cloudevents-sdk-actix-web`: Integration with [Actix Web](https://github.com/actix/actix-web).
25+
* `cloudevents-sdk-reqwest`: Integration with [reqwest](https://github.com/seanmonstar/reqwest).
26+
27+
## Get Started
28+
29+
To get started, add the dependency to `Cargo.toml`:
30+
31+
```toml
32+
cloudevents-sdk = "0.1.0"
33+
```
34+
35+
Now you can start creating events:
36+
37+
```rust
38+
use cloudevents::EventBuilder;
39+
use url::Url;
40+
41+
let event = EventBuilder::v03()
42+
.id("aaa")
43+
.source(Url::parse("http://localhost").unwrap())
44+
.ty("example.demo")
45+
.build();
46+
```
47+
48+
Checkout the examples using our integrations with `actix-web` and `reqwest` to learn how to send and receive events:
49+
50+
* [Actix Web Example](example-projects/actix-web-example)
51+
* [Reqwest/WASM Example](example-projects/reqwest-wasm-example)
2452

2553
## Development & Contributing
2654

@@ -38,5 +66,10 @@ If you're interested in contributing to sdk-rust, look at [Contributing document
3866
- Slack: #cloudeventssdk (or #cloudevents-sdk-rust) channel under
3967
[CNCF's Slack workspace](https://slack.cncf.io/).
4068
- Email: https://lists.cncf.io/g/cncf-cloudevents-sdk
41-
- Contact for additional information: Fancesco Guardiani (`@slinkydeveloper`
69+
- Contact for additional information: Francesco Guardiani (`@slinkydeveloper`
4270
on slack).
71+
72+
[Crates badge]: https://img.shields.io/crates/v/cloudevents-sdk.svg
73+
[crates.io]: https://crates.io/crates/cloudevents-sdk
74+
[Docs badge]: https://docs.rs/cloudevents-sdk/badge.svg
75+
[docs.rs]: https://docs.rs/cloudevents-sdk

cloudevents-sdk-actix-web/src/headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ fn attributes_to_headers(
6262

6363
lazy_static! {
6464
pub(crate) static ref ATTRIBUTES_TO_HEADERS: HashMap<&'static str, HeaderName> =
65-
attributes_to_headers(&cloudevents::event::spec_version::ATTRIBUTE_NAMES);
65+
attributes_to_headers(&cloudevents::event::SPEC_VERSION_ATTRIBUTES);
6666
pub(crate) static ref SPEC_VERSION_HEADER: HeaderName =
6767
HeaderName::from_static("ce-specversion");
6868
pub(crate) static ref CLOUDEVENTS_JSON_HEADER: HeaderValue =

cloudevents-sdk-actix-web/src/server_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'a> BinaryDeserializer for HttpRequestDeserializer<'a> {
3535

3636
visitor = visitor.set_spec_version(spec_version.clone())?;
3737

38-
let attributes = cloudevents::event::spec_version::ATTRIBUTE_NAMES
38+
let attributes = cloudevents::event::SPEC_VERSION_ATTRIBUTES
3939
.get(&spec_version)
4040
.unwrap();
4141

cloudevents-sdk-actix-web/src/server_response.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ use cloudevents::message::{
99
use cloudevents::Event;
1010
use std::str::FromStr;
1111

12+
/// Wrapper for [`HttpResponseBuilder`] that implements [`StructuredSerializer`] and [`BinarySerializer`]
1213
pub struct HttpResponseSerializer {
1314
builder: HttpResponseBuilder,
1415
}

cloudevents-sdk-reqwest/src/client_request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl StructuredSerializer<RequestBuilder> for RequestSerializer {
6262
}
6363
}
6464

65-
/// Method to transform an incoming [`HttpRequest`] to [`Event`]
65+
/// Method to fill a [`RequestBuilder`] with an [`Event`]
6666
pub fn event_to_request(event: Event, request_builder: RequestBuilder) -> Result<RequestBuilder> {
6767
BinaryDeserializer::deserialize_binary(event, RequestSerializer::new(request_builder))
6868
}

cloudevents-sdk-reqwest/src/client_response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ impl BinaryDeserializer for ResponseDeserializer {
3434

3535
visitor = visitor.set_spec_version(spec_version.clone())?;
3636

37-
let attributes = cloudevents::event::spec_version::ATTRIBUTE_NAMES
37+
let attributes = cloudevents::event::SPEC_VERSION_ATTRIBUTES
3838
.get(&spec_version)
3939
.unwrap();
4040

cloudevents-sdk-reqwest/src/headers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn attributes_to_headers(
5555

5656
lazy_static! {
5757
pub(crate) static ref ATTRIBUTES_TO_HEADERS: HashMap<&'static str, HeaderName> =
58-
attributes_to_headers(&cloudevents::event::spec_version::ATTRIBUTE_NAMES);
58+
attributes_to_headers(&cloudevents::event::SPEC_VERSION_ATTRIBUTES);
5959
pub(crate) static ref SPEC_VERSION_HEADER: HeaderName =
6060
HeaderName::from_static("ce-specversion");
6161
pub(crate) static ref CLOUDEVENTS_JSON_HEADER: HeaderValue =

src/event/attributes.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,17 @@ pub trait AttributesReader {
4444
fn get_time(&self) -> Option<&DateTime<Utc>>;
4545
}
4646

47+
/// Trait to set [CloudEvents Context attributes](https://github.com/cloudevents/spec/blob/master/spec.md#context-attributes).
4748
pub trait AttributesWriter {
49+
/// Set the [id](https://github.com/cloudevents/spec/blob/master/spec.md#id).
4850
fn set_id(&mut self, id: impl Into<String>);
51+
/// Set the [source](https://github.com/cloudevents/spec/blob/master/spec.md#source-1).
4952
fn set_source(&mut self, source: impl Into<Url>);
53+
/// Set the [type](https://github.com/cloudevents/spec/blob/master/spec.md#type).
5054
fn set_type(&mut self, ty: impl Into<String>);
55+
/// Set the [subject](https://github.com/cloudevents/spec/blob/master/spec.md#subject).
5156
fn set_subject(&mut self, subject: Option<impl Into<String>>);
57+
/// Set the [time](https://github.com/cloudevents/spec/blob/master/spec.md#time).
5258
fn set_time(&mut self, time: Option<impl Into<DateTime<Utc>>>);
5359
}
5460

@@ -62,6 +68,7 @@ pub(crate) trait DataAttributesWriter {
6268
fn set_dataschema(&mut self, dataschema: Option<impl Into<Url>>);
6369
}
6470

71+
/// Union type representing one of the possible context attributes structs
6572
#[derive(PartialEq, Debug, Clone)]
6673
pub enum Attributes {
6774
V03(AttributesV03),

src/event/builder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use super::{EventBuilderV03, EventBuilderV10};
22

3-
/// Builder to create [`Event`]:
3+
/// Builder to create [`super::Event`]:
44
/// ```
55
/// use cloudevents::EventBuilder;
66
/// use chrono::Utc;

0 commit comments

Comments
 (0)