File tree Expand file tree Collapse file tree 4 files changed +27
-6
lines changed
cloudevents-sdk-actix-web Expand file tree Collapse file tree 4 files changed +27
-6
lines changed Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ description = "CloudEvents official Rust SDK - Actix-Web integration"
88documentation = " https://docs.rs/cloudevents-sdk-actix-web"
99repository = " https://github.com/cloudevents/sdk-rust"
1010readme = " README.md"
11+ categories = [" web-programming" , " encoding" , " web-programming::http-server" ]
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 33//! To deserialize an HTTP request as CloudEvent:
44//!
55//! ```
6- //! use cloudevents_sdk_actix_web::RequestExt ;
6+ //! use cloudevents_sdk_actix_web::HttpRequestExt ;
77//! use actix_web::{HttpRequest, web, post};
88//!
99//! #[post("/")]
4141//!
4242//! Check out the [cloudevents-sdk](https://docs.rs/cloudevents-sdk) docs for more details on how to use [`cloudevents::Event`]
4343
44+ #![ deny( broken_intra_doc_links) ]
45+
4446#[ macro_use]
4547mod headers;
4648mod server_request;
4749mod server_response;
4850
4951pub use server_request:: request_to_event;
5052pub use server_request:: HttpRequestDeserializer ;
51- pub use server_request:: RequestExt ;
53+ pub use server_request:: HttpRequestExt ;
5254pub use server_response:: event_to_response;
5355pub use server_response:: HttpResponseBuilderExt ;
5456pub use server_response:: HttpResponseSerializer ;
Original file line number Diff line number Diff line change @@ -113,16 +113,19 @@ pub async fn request_to_event(
113113}
114114
115115/// Extention Trait for [`HttpRequest`] which acts as a wrapper for the function [`request_to_event()`].
116+ ///
117+ /// This trait is sealed and cannot be implemented for types outside of this crate.
116118#[ async_trait( ?Send ) ]
117- pub trait RequestExt {
119+ pub trait HttpRequestExt : private:: Sealed {
120+ /// Convert this [`HttpRequest`] into an [`Event`].
118121 async fn to_event (
119122 & self ,
120123 mut payload : web:: Payload ,
121124 ) -> std:: result:: Result < Event , actix_web:: error:: Error > ;
122125}
123126
124127#[ async_trait( ?Send ) ]
125- impl RequestExt for HttpRequest {
128+ impl HttpRequestExt for HttpRequest {
126129 async fn to_event (
127130 & self ,
128131 payload : web:: Payload ,
@@ -131,6 +134,12 @@ impl RequestExt for HttpRequest {
131134 }
132135}
133136
137+ mod private {
138+ // Sealing the RequestExt
139+ pub trait Sealed { }
140+ impl Sealed for actix_web:: HttpRequest { }
141+ }
142+
134143#[ cfg( test) ]
135144mod tests {
136145 use super :: * ;
Original file line number Diff line number Diff line change @@ -76,9 +76,12 @@ pub async fn event_to_response(
7676 . map_err ( actix_web:: error:: ErrorBadRequest )
7777}
7878
79- /// Extention Trait for [`HttpResponseBuilder`] which acts as a wrapper for the function [`event_to_response()`].
79+ /// Extension Trait for [`HttpResponseBuilder`] which acts as a wrapper for the function [`event_to_response()`].
80+ ///
81+ /// This trait is sealed and cannot be implemented for types outside of this crate.
8082#[ async_trait( ?Send ) ]
81- pub trait HttpResponseBuilderExt {
83+ pub trait HttpResponseBuilderExt : private:: Sealed {
84+ /// Fill this [`HttpResponseBuilder`] with an [`Event`].
8285 async fn event (
8386 self ,
8487 event : Event ,
@@ -95,6 +98,12 @@ impl HttpResponseBuilderExt for HttpResponseBuilder {
9598 }
9699}
97100
101+ // Sealing the HttpResponseBuilderExt
102+ mod private {
103+ pub trait Sealed { }
104+ impl Sealed for actix_web:: dev:: HttpResponseBuilder { }
105+ }
106+
98107#[ cfg( test) ]
99108mod tests {
100109 use super :: * ;
You can’t perform that action at this time.
0 commit comments