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"
88documentation = " https://docs.rs/cloudevents-sdk-reqwest"
99repository = " https://github.com/cloudevents/sdk-rust"
1010readme = " README.md"
11+ categories = [" web-programming" , " encoding" , " web-programming::http-client" ]
1112
1213# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
1314
Original file line number Diff line number Diff line change @@ -62,13 +62,16 @@ impl StructuredSerializer<RequestBuilder> for RequestSerializer {
6262 }
6363}
6464
65- /// Method to fill a [`RequestBuilder`] with an [`Event`]
65+ /// Method to fill a [`RequestBuilder`] with an [`Event`].
6666pub fn event_to_request ( event : Event , request_builder : RequestBuilder ) -> Result < RequestBuilder > {
6767 BinaryDeserializer :: deserialize_binary ( event, RequestSerializer :: new ( request_builder) )
6868}
6969
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`].
7275 fn event ( self , event : Event ) -> Result < RequestBuilder > ;
7376}
7477
@@ -78,6 +81,12 @@ impl RequestBuilderExt for RequestBuilder {
7881 }
7982}
8083
84+ // Sealing the RequestBuilderExt
85+ mod private {
86+ pub trait Sealed { }
87+ impl Sealed for reqwest:: RequestBuilder { }
88+ }
89+
8190#[ cfg( test) ]
8291mod tests {
8392 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> {
109109}
110110
111111/// 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.
112114#[ async_trait( ?Send ) ]
113- pub trait ResponseExt {
115+ pub trait ResponseExt : private:: Sealed {
116+ /// Convert this [`Response`] to [`Event`].
114117 async fn into_event ( self ) -> Result < Event > ;
115118}
116119
@@ -121,6 +124,12 @@ impl ResponseExt for Response {
121124 }
122125}
123126
127+ // Sealing the ResponseExt
128+ mod private {
129+ pub trait Sealed { }
130+ impl Sealed for reqwest:: Response { }
131+ }
132+
124133#[ cfg( test) ]
125134mod tests {
126135 use super :: * ;
Original file line number Diff line number Diff line change 55//! use cloudevents::{EventBuilderV10, EventBuilder};
66//! use serde_json::json;
77//!
8- //! # async fn example() {
8+ //! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
99//! let client = reqwest::Client::new();
1010//!
1111//! // Prepare the event to send
1414//! .ty("example.test")
1515//! .source("http://localhost/")
1616//! .data("application/json", json!({"hello": "world"}))
17- //! .build()
18- //! .expect("No error while building the event");
17+ //! .build()?;
1918//!
2019//! // Send request
2120//! 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?;
2623//! // Parse response as event
2724//! let received_event = response
28- //! .into_event().await
29- //! .expect("Error while deserializing the response");
25+ //! .into_event().await?;
26+ //! # Ok(())
3027//! # }
3128//! ```
3229//!
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) ]
3433
3534#[ macro_use]
3635mod headers;
You can’t perform that action at this time.
0 commit comments