File tree Expand file tree Collapse file tree 4 files changed +32
-14
lines changed Expand file tree Collapse file tree 4 files changed +32
-14
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ description = "CloudEvents official Rust SDK - Reqwest integration"
8
8
documentation = " https://docs.rs/cloudevents-sdk-reqwest"
9
9
repository = " https://github.com/cloudevents/sdk-rust"
10
10
readme = " README.md"
11
+ categories = [" web-programming" , " encoding" , " web-programming::http-client" ]
11
12
12
13
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
13
14
Original file line number Diff line number Diff line change @@ -62,13 +62,16 @@ impl StructuredSerializer<RequestBuilder> for RequestSerializer {
62
62
}
63
63
}
64
64
65
- /// Method to fill a [`RequestBuilder`] with an [`Event`]
65
+ /// Method to fill a [`RequestBuilder`] with an [`Event`].
66
66
pub fn event_to_request ( event : Event , request_builder : RequestBuilder ) -> Result < RequestBuilder > {
67
67
BinaryDeserializer :: deserialize_binary ( event, RequestSerializer :: new ( request_builder) )
68
68
}
69
69
70
- /// Extention Trait for [`RequestBuilder`] which acts as a wrapper for the function [`event_to_request()`]
71
- pub trait RequestBuilderExt {
70
+ /// Extension Trait for [`RequestBuilder`] which acts as a wrapper for the function [`event_to_request()`].
71
+ ///
72
+ /// This trait is sealed and cannot be implemented for types outside of this crate.
73
+ pub trait RequestBuilderExt : private:: Sealed {
74
+ /// Write in this [`RequestBuilder`] the provided [`Event`]. Similar to invoking [`Event`].
72
75
fn event ( self , event : Event ) -> Result < RequestBuilder > ;
73
76
}
74
77
@@ -78,6 +81,12 @@ impl RequestBuilderExt for RequestBuilder {
78
81
}
79
82
}
80
83
84
+ // Sealing the RequestBuilderExt
85
+ mod private {
86
+ pub trait Sealed { }
87
+ impl Sealed for reqwest:: RequestBuilder { }
88
+ }
89
+
81
90
#[ cfg( test) ]
82
91
mod tests {
83
92
use super :: * ;
Original file line number Diff line number Diff line change @@ -109,8 +109,11 @@ pub async fn response_to_event(res: Response) -> Result<Event> {
109
109
}
110
110
111
111
/// Extension Trait for [`Response`] which acts as a wrapper for the function [`response_to_event()`].
112
+ ///
113
+ /// This trait is sealed and cannot be implemented for types outside of this crate.
112
114
#[ async_trait( ?Send ) ]
113
- pub trait ResponseExt {
115
+ pub trait ResponseExt : private:: Sealed {
116
+ /// Convert this [`Response`] to [`Event`].
114
117
async fn into_event ( self ) -> Result < Event > ;
115
118
}
116
119
@@ -121,6 +124,12 @@ impl ResponseExt for Response {
121
124
}
122
125
}
123
126
127
+ // Sealing the ResponseExt
128
+ mod private {
129
+ pub trait Sealed { }
130
+ impl Sealed for reqwest:: Response { }
131
+ }
132
+
124
133
#[ cfg( test) ]
125
134
mod tests {
126
135
use super :: * ;
Original file line number Diff line number Diff line change 5
5
//! use cloudevents::{EventBuilderV10, EventBuilder};
6
6
//! use serde_json::json;
7
7
//!
8
- //! # async fn example() {
8
+ //! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
9
9
//! let client = reqwest::Client::new();
10
10
//!
11
11
//! // Prepare the event to send
14
14
//! .ty("example.test")
15
15
//! .source("http://localhost/")
16
16
//! .data("application/json", json!({"hello": "world"}))
17
- //! .build()
18
- //! .expect("No error while building the event");
17
+ //! .build()?;
19
18
//!
20
19
//! // Send request
21
20
//! let response = client.post("http://localhost")
22
- //! .event(event_to_send)
23
- //! .expect("Error while serializing the event")
24
- //! .send().await
25
- //! .expect("Error while sending the request");
21
+ //! .event(event_to_send)?
22
+ //! .send().await?;
26
23
//! // Parse response as event
27
24
//! let received_event = response
28
- //! .into_event().await
29
- //! .expect("Error while deserializing the response");
25
+ //! .into_event().await?;
26
+ //! # Ok(())
30
27
//! # }
31
28
//! ```
32
29
//!
33
- //! Check out the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) docs for more details on how to use [`cloudevents::Event`]
30
+ //! Check out the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) docs for more details on how to use [`cloudevents::Event`].
31
+
32
+ #![ deny( broken_intra_doc_links) ]
34
33
35
34
#[ macro_use]
36
35
mod headers;
You can’t perform that action at this time.
0 commit comments