@@ -19,21 +19,21 @@ use std::ops::{Deref, DerefMut};
1919/// # As extractor
2020///
2121/// When used as an extractor, it can decode request bodies into some type that
22- /// implements [`prost::Message`]. The request will be rejected (and a [`ProtoBufRejection `] will
22+ /// implements [`prost::Message`]. The request will be rejected (and a [`ProtobufRejection `] will
2323/// be returned) if:
2424///
2525/// - The body couldn't be decoded into the target Protocol Buffer message type.
2626/// - Buffering the request body fails.
2727///
28- /// See [`ProtoBufRejection `] for more details.
28+ /// See [`ProtobufRejection `] for more details.
2929///
3030/// The extractor does not expect a `Content-Type` header to be present in the request.
3131///
3232/// # Extractor example
3333///
3434/// ```rust,no_run
3535/// use axum::{routing::post, Router};
36- /// use axum_extra::protobuf::ProtoBuf ;
36+ /// use axum_extra::protobuf::Protobuf ;
3737///
3838/// #[derive(prost::Message)]
3939/// struct CreateUser {
@@ -43,7 +43,7 @@ use std::ops::{Deref, DerefMut};
4343/// password: String,
4444/// }
4545///
46- /// async fn create_user(ProtoBuf (payload): ProtoBuf <CreateUser>) {
46+ /// async fn create_user(Protobuf (payload): Protobuf <CreateUser>) {
4747/// // payload is `CreateUser`
4848/// }
4949///
@@ -69,17 +69,17 @@ use std::ops::{Deref, DerefMut};
6969/// routing::get,
7070/// Router,
7171/// };
72- /// use axum_extra::protobuf::ProtoBuf ;
72+ /// use axum_extra::protobuf::Protobuf ;
7373///
7474/// #[derive(prost::Message)]
7575/// struct User {
7676/// #[prost(string, tag="1")]
7777/// username: String,
7878/// }
7979///
80- /// async fn get_user(Path(user_id) : Path<String>) -> ProtoBuf <User> {
80+ /// async fn get_user(Path(user_id) : Path<String>) -> Protobuf <User> {
8181/// let user = find_user(user_id).await;
82- /// ProtoBuf (user)
82+ /// Protobuf (user)
8383/// }
8484///
8585/// async fn find_user(user_id: String) -> User {
@@ -94,50 +94,50 @@ use std::ops::{Deref, DerefMut};
9494/// ```
9595#[ derive( Debug , Clone , Copy , Default ) ]
9696#[ cfg_attr( docsrs, doc( cfg( feature = "protobuf" ) ) ) ]
97- pub struct ProtoBuf < T > ( pub T ) ;
97+ pub struct Protobuf < T > ( pub T ) ;
9898
9999#[ async_trait]
100- impl < T , S , B > FromRequest < S , B > for ProtoBuf < T >
100+ impl < T , S , B > FromRequest < S , B > for Protobuf < T >
101101where
102102 T : Message + Default ,
103103 B : HttpBody + Send + ' static ,
104104 B :: Data : Send ,
105105 B :: Error : Into < BoxError > ,
106106 S : Send + Sync ,
107107{
108- type Rejection = ProtoBufRejection ;
108+ type Rejection = ProtobufRejection ;
109109
110110 async fn from_request ( req : Request < B > , state : & S ) -> Result < Self , Self :: Rejection > {
111111 let mut bytes = Bytes :: from_request ( req, state) . await ?;
112112
113113 match T :: decode ( & mut bytes) {
114- Ok ( value) => Ok ( ProtoBuf ( value) ) ,
115- Err ( err) => Err ( ProtoBufDecodeError :: from_err ( err) . into ( ) ) ,
114+ Ok ( value) => Ok ( Protobuf ( value) ) ,
115+ Err ( err) => Err ( ProtobufDecodeError :: from_err ( err) . into ( ) ) ,
116116 }
117117 }
118118}
119119
120- impl < T > Deref for ProtoBuf < T > {
120+ impl < T > Deref for Protobuf < T > {
121121 type Target = T ;
122122
123123 fn deref ( & self ) -> & Self :: Target {
124124 & self . 0
125125 }
126126}
127127
128- impl < T > DerefMut for ProtoBuf < T > {
128+ impl < T > DerefMut for Protobuf < T > {
129129 fn deref_mut ( & mut self ) -> & mut Self :: Target {
130130 & mut self . 0
131131 }
132132}
133133
134- impl < T > From < T > for ProtoBuf < T > {
134+ impl < T > From < T > for Protobuf < T > {
135135 fn from ( inner : T ) -> Self {
136136 Self ( inner)
137137 }
138138}
139139
140- impl < T > IntoResponse for ProtoBuf < T >
140+ impl < T > IntoResponse for Protobuf < T >
141141where
142142 T : Message + Default ,
143143{
@@ -150,13 +150,13 @@ where
150150 }
151151}
152152
153- /// Rejection type for [`ProtoBuf `].
153+ /// Rejection type for [`Protobuf `].
154154///
155155/// This rejection is used if the request body couldn't be decoded into the target type.
156156#[ derive( Debug ) ]
157- pub struct ProtoBufDecodeError ( pub ( crate ) axum:: Error ) ;
157+ pub struct ProtobufDecodeError ( pub ( crate ) axum:: Error ) ;
158158
159- impl ProtoBufDecodeError {
159+ impl ProtobufDecodeError {
160160 pub ( crate ) fn from_err < E > ( err : E ) -> Self
161161 where
162162 E : Into < axum:: BoxError > ,
@@ -165,53 +165,53 @@ impl ProtoBufDecodeError {
165165 }
166166}
167167
168- impl std:: fmt:: Display for ProtoBufDecodeError {
168+ impl std:: fmt:: Display for ProtobufDecodeError {
169169 fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
170170 write ! ( f, "Failed to decode the body: {:?}" , self . 0 )
171171 }
172172}
173173
174- impl std:: error:: Error for ProtoBufDecodeError {
174+ impl std:: error:: Error for ProtobufDecodeError {
175175 fn source ( & self ) -> Option < & ( dyn std:: error:: Error + ' static ) > {
176176 Some ( & self . 0 )
177177 }
178178}
179179
180- impl IntoResponse for ProtoBufDecodeError {
180+ impl IntoResponse for ProtobufDecodeError {
181181 fn into_response ( self ) -> Response {
182182 StatusCode :: UNPROCESSABLE_ENTITY . into_response ( )
183183 }
184184}
185185
186- /// Rejection used for [`ProtoBuf `].
186+ /// Rejection used for [`Protobuf `].
187187///
188- /// Contains one variant for each way the [`ProtoBuf `] extractor
188+ /// Contains one variant for each way the [`Protobuf `] extractor
189189/// can fail.
190190#[ derive( Debug ) ]
191191#[ non_exhaustive]
192- pub enum ProtoBufRejection {
192+ pub enum ProtobufRejection {
193193 #[ allow( missing_docs) ]
194- ProtoBufDecodeError ( ProtoBufDecodeError ) ,
194+ ProtobufDecodeError ( ProtobufDecodeError ) ,
195195 #[ allow( missing_docs) ]
196196 BytesRejection ( BytesRejection ) ,
197197}
198198
199- impl From < ProtoBufDecodeError > for ProtoBufRejection {
200- fn from ( inner : ProtoBufDecodeError ) -> Self {
201- Self :: ProtoBufDecodeError ( inner)
199+ impl From < ProtobufDecodeError > for ProtobufRejection {
200+ fn from ( inner : ProtobufDecodeError ) -> Self {
201+ Self :: ProtobufDecodeError ( inner)
202202 }
203203}
204204
205- impl From < BytesRejection > for ProtoBufRejection {
205+ impl From < BytesRejection > for ProtobufRejection {
206206 fn from ( inner : BytesRejection ) -> Self {
207207 Self :: BytesRejection ( inner)
208208 }
209209}
210210
211- impl IntoResponse for ProtoBufRejection {
211+ impl IntoResponse for ProtobufRejection {
212212 fn into_response ( self ) -> Response {
213213 match self {
214- Self :: ProtoBufDecodeError ( inner) => inner. into_response ( ) ,
214+ Self :: ProtobufDecodeError ( inner) => inner. into_response ( ) ,
215215 Self :: BytesRejection ( inner) => inner. into_response ( ) ,
216216 }
217217 }
@@ -234,7 +234,7 @@ mod tests {
234234
235235 let app = Router :: new ( ) . route (
236236 "/" ,
237- post ( |input : ProtoBuf < Input > | async move { input. foo . to_owned ( ) } ) ,
237+ post ( |input : Protobuf < Input > | async move { input. foo . to_owned ( ) } ) ,
238238 ) ;
239239
240240 let input = Input {
@@ -263,7 +263,7 @@ mod tests {
263263 test : i32 ,
264264 }
265265
266- let app = Router :: new ( ) . route ( "/" , post ( |_: ProtoBuf < Expected > | async { } ) ) ;
266+ let app = Router :: new ( ) . route ( "/" , post ( |_: Protobuf < Expected > | async { } ) ) ;
267267
268268 let input = Input {
269269 foo : "bar" . to_owned ( ) ,
@@ -291,12 +291,12 @@ mod tests {
291291
292292 let app = Router :: new ( ) . route (
293293 "/" ,
294- post ( |input : ProtoBuf < Input > | async move {
294+ post ( |input : Protobuf < Input > | async move {
295295 let output = Output {
296296 result : input. foo . to_owned ( ) ,
297297 } ;
298298
299- ProtoBuf ( output)
299+ Protobuf ( output)
300300 } ) ,
301301 ) ;
302302
0 commit comments