Skip to content

Commit 6133a6e

Browse files
Docs in cloudevents-sdk-reqwest
Signed-off-by: Francesco Guardiani <[email protected]>
1 parent e330c6c commit 6133a6e

File tree

4 files changed

+32
-14
lines changed

4 files changed

+32
-14
lines changed

cloudevents-sdk-reqwest/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ description = "CloudEvents official Rust SDK - Reqwest integration"
88
documentation = "https://docs.rs/cloudevents-sdk-reqwest"
99
repository = "https://github.com/cloudevents/sdk-rust"
1010
readme = "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

cloudevents-sdk-reqwest/src/client_request.rs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff 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`].
6666
pub 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)]
8291
mod tests {
8392
use super::*;

cloudevents-sdk-reqwest/src/client_response.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff 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)]
125134
mod tests {
126135
use super::*;

cloudevents-sdk-reqwest/src/lib.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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
@@ -14,23 +14,22 @@
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]
3635
mod headers;

0 commit comments

Comments
 (0)