Skip to content

Commit 90fcc07

Browse files
committed
feat: update rustfmt config
1 parent 12bdea4 commit 90fcc07

File tree

10 files changed

+88
-66
lines changed

10 files changed

+88
-66
lines changed

macros/src/lib.rs

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ pub fn apply(
2525
mod apply {
2626
use proc_macro2::TokenStream;
2727
use quote::{quote, ToTokens};
28-
2928
use syn::{
3029
parse::{Parse, ParseStream},
3130
punctuated::Punctuated,
@@ -75,9 +74,7 @@ mod apply {
7574
Some(other) => {
7675
return Err(syn::Error::new(
7776
path.span(),
78-
format!(
79-
"unknown option `{other}`, expected `encode` or `decode`"
80-
),
77+
format!("unknown option `{other}`, expected `encode` or `decode`"),
8178
))
8279
}
8380
None => {
@@ -90,10 +87,7 @@ mod apply {
9087
}
9188
Meta::NameValue(name_value) => {
9289
if !name_value.path.is_ident("crate") {
93-
return Err(syn::Error::new(
94-
name_value.path.span(),
95-
"expected `crate`",
96-
));
90+
return Err(syn::Error::new(name_value.path.span(), "expected `crate`"));
9791
}
9892

9993
let path = match name_value.value {
@@ -109,8 +103,7 @@ mod apply {
109103
}
110104
};
111105

112-
let mut path =
113-
syn::parse_str::<Path>(&path.value()).expect("failed to parse path");
106+
let mut path = syn::parse_str::<Path>(&path.value()).expect("failed to parse path");
114107

115108
path.leading_colon = if path.is_ident("crate") {
116109
None

rustfmt.toml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
11
hard_tabs = true
2+
tab_spaces = 2
3+
newline_style = "Unix"
4+
5+
group_imports = "StdExternalCrate"
6+
imports_granularity = "Crate"
7+
8+
format_code_in_doc_comments = true
9+
format_macro_matchers = true
10+
format_strings = true
11+
hex_literal_case = "Lower"
12+
use_field_init_shorthand = true
13+
condense_wildcard_suffixes = true
14+
15+
normalize_comments = true
16+
normalize_doc_attributes = true
17+
overflow_delimited_expr = true
18+
wrap_comments = true
19+
20+
reorder_impl_items = true
221
reorder_imports = true
322

src/content.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ pub enum ContentType {
3535
feature = "toml"
3636
)))]
3737
const _: () = {
38-
compile_error!("At least one of the following features must be enabled: `json`, `msgpack`, `bincode`, `bitcode`, `cbor`, `yaml`, `toml`.");
38+
compile_error!(
39+
"At least one of the following features must be enabled: `json`, `msgpack`, `bincode`, \
40+
`bitcode`, `cbor`, `yaml`, `toml`."
41+
);
3942

4043
impl Default for ContentType {
4144
fn default() -> Self {
@@ -232,16 +235,16 @@ impl<S> FromRequestParts<S> for ContentType {
232235
/// #
233236
/// #[axum_codec::apply(encode)]
234237
/// struct User {
235-
/// name: String,
236-
/// age: u8,
238+
/// name: String,
239+
/// age: u8,
237240
/// }
238241
///
239242
/// fn get_user(accept: Accept) -> impl IntoResponse {
240-
/// Codec(User {
241-
/// name: "Alice".into(),
242-
/// age: 42,
243-
/// })
244-
/// .to_response(accept)
243+
/// Codec(User {
244+
/// name: "Alice".into(),
245+
/// age: 42,
246+
/// })
247+
/// .to_response(accept)
245248
/// }
246249
/// #
247250
/// # fn main() {}

src/decode.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ where
2525
}
2626

2727
/// Attempts to deserialize the given bytes as [MessagePack](https://msgpack.org).
28-
/// Does not perform any validation if the `validator` feature is enabled. For validation,
29-
/// use [`Self::from_bytes`].
28+
/// Does not perform any validation if the `validator` feature is enabled. For
29+
/// validation, use [`Self::from_bytes`].
3030
///
3131
/// # Errors
3232
///
@@ -38,8 +38,8 @@ where
3838
}
3939

4040
/// Attemps to deserialize the given bytes as [CBOR](https://cbor.io).
41-
/// Does not perform any validation if the `validator` feature is enabled. For validation,
42-
/// use [`Self::from_bytes`].
41+
/// Does not perform any validation if the `validator` feature is enabled. For
42+
/// validation, use [`Self::from_bytes`].
4343
///
4444
/// # Errors
4545
///
@@ -51,8 +51,8 @@ where
5151
}
5252

5353
/// Attempts to deserialize the given text as [YAML](https://yaml.org).
54-
/// Does not perform any validation if the `validator` feature is enabled. For validation,
55-
/// use [`Self::from_bytes`].
54+
/// Does not perform any validation if the `validator` feature is enabled. For
55+
/// validation, use [`Self::from_bytes`].
5656
///
5757
/// # Errors
5858
///
@@ -64,8 +64,8 @@ where
6464
}
6565

6666
/// Attempts to deserialize the given text as [TOML](https://toml.io).
67-
/// Does not perform any validation if the `validator` feature is enabled. For validation,
68-
/// use [`Self::from_bytes`].
67+
/// Does not perform any validation if the `validator` feature is enabled. For
68+
/// validation, use [`Self::from_bytes`].
6969
///
7070
/// # Errors
7171
///
@@ -79,8 +79,8 @@ where
7979

8080
impl<T> Codec<T> {
8181
/// Attempts to deserialize the given bytes as [Bincode](https://github.com/bincode-org/bincode).
82-
/// Does not perform any validation if the `validator` feature is enabled. For validation,
83-
/// use [`Self::from_bytes`].
82+
/// Does not perform any validation if the `validator` feature is enabled. For
83+
/// validation, use [`Self::from_bytes`].
8484
///
8585
/// # Errors
8686
///
@@ -95,8 +95,8 @@ impl<T> Codec<T> {
9595
}
9696

9797
/// Attempts to deserialize the given bytes as [Bitcode](https://github.com/SoftbearStudios/bitcode).
98-
/// Does not perform any validation if the `validator` feature is enabled. For validation,
99-
/// use [`Self::from_bytes`].
98+
/// Does not perform any validation if the `validator` feature is enabled. For
99+
/// validation, use [`Self::from_bytes`].
100100
///
101101
/// # Errors
102102
///

src/extract.rs

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@ use crate::{Accept, CodecDecode, CodecEncode, CodecRejection, ContentType, IntoC
1515
/// The serialized data is not specified. Upon deserialization, the request's
1616
/// `Content-Type` header is used to determine the format of the data.
1717
///
18-
/// By default, only JSON is supported. To enable other formats, use the corresponding feature flags.
18+
/// By default, only JSON is supported. To enable other formats, use the
19+
/// corresponding feature flags.
1920
///
20-
/// Note that [`IntoResponse`] is not implemented for this type, as the headers are not available
21-
/// when serializing the data. Instead, use [`Codec::to_response`] to create a response with the
22-
/// appropriate `Content-Type` header extracted from the request with [`Accept`].
21+
/// Note that [`IntoResponse`] is not implemented for this type, as the headers
22+
/// are not available when serializing the data. Instead, use
23+
/// [`Codec::to_response`] to create a response with the appropriate
24+
/// `Content-Type` header extracted from the request with [`Accept`].
2325
///
2426
/// # Examples
2527
///
@@ -31,7 +33,7 @@ use crate::{Accept, CodecDecode, CodecEncode, CodecRejection, ContentType, IntoC
3133
/// # fn main() {
3234
/// #[axum_codec::apply(decode)]
3335
/// struct Greeting {
34-
/// hello: String
36+
/// hello: String,
3537
/// }
3638
///
3739
/// let bytes = b"{\"hello\": \"world\"}";
@@ -55,7 +57,8 @@ where
5557

5658
/// Converts the inner value into a response with the given content type.
5759
///
58-
/// If serialization fails, the rejection is converted into a response. See [`encode::Error`](crate::encode::Error) for possible errors.
60+
/// If serialization fails, the rejection is converted into a response. See
61+
/// [`encode::Error`](crate::encode::Error) for possible errors.
5962
pub fn to_response<C: Into<ContentType>>(&self, content_type: C) -> Response {
6063
let content_type = content_type.into();
6164
let bytes = match self.to_bytes(content_type) {
@@ -113,8 +116,8 @@ where
113116
let bytes = Bytes::from_request(req, state)
114117
.await
115118
.map_err(|e| CodecRejection::from(e).into_codec_response(accept.into()))?;
116-
let data = Codec::from_bytes(&bytes, content_type)
117-
.map_err(|e| e.into_codec_response(accept.into()))?;
119+
let data =
120+
Codec::from_bytes(&bytes, content_type).map_err(|e| e.into_codec_response(accept.into()))?;
118121

119122
Ok(data)
120123
}
@@ -185,12 +188,9 @@ mod test {
185188

186189
let Codec(data) = Codec::<Data>::from_bytes(bytes, ContentType::Json).unwrap();
187190

188-
assert_eq!(
189-
data,
190-
Data {
191-
hello: "world".into()
192-
}
193-
);
191+
assert_eq!(data, Data {
192+
hello: "world".into()
193+
});
194194
}
195195

196196
#[test]
@@ -199,11 +199,8 @@ mod test {
199199

200200
let Codec(data) = Codec::<Data>::from_bytes(bytes, ContentType::MsgPack).unwrap();
201201

202-
assert_eq!(
203-
data,
204-
Data {
205-
hello: "world".into()
206-
}
207-
);
202+
assert_eq!(data, Data {
203+
hello: "world".into()
204+
});
208205
}
209206
}

src/handler.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub trait CodecHandler<T, I: Input, D, S>: Clone + Send + 'static {
2828
fn call(self, req: Request, state: S) -> Self::Future;
2929
}
3030

31-
/// Transforms a function (that returns [`IntoCodecResponse`]) into a regular handler.
31+
/// Transforms a function (that returns [`IntoCodecResponse`]) into a regular
32+
/// handler.
3233
pub struct CodecHandlerFn<H, I, D> {
3334
pub(crate) f: H,
3435
pub(crate) _marker: std::marker::PhantomData<(I, D)>,

src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@ pub mod rejection;
1212
pub mod response;
1313
pub mod routing;
1414

15-
pub use {
16-
content::{Accept, ContentType},
17-
decode::CodecDecode,
18-
encode::CodecEncode,
19-
extract::*,
20-
handler::CodecHandler,
21-
rejection::CodecRejection,
22-
response::IntoCodecResponse,
23-
};
15+
pub use content::{Accept, ContentType};
16+
pub use decode::CodecDecode;
17+
pub use encode::CodecEncode;
18+
pub use extract::*;
19+
pub use handler::CodecHandler;
20+
pub use rejection::CodecRejection;
21+
pub use response::IntoCodecResponse;
2422

2523
#[doc(hidden)]
2624
pub mod __private {
@@ -37,6 +35,5 @@ pub mod __private {
3735
}
3836

3937
pub use axum_codec_macros as macros;
40-
4138
#[cfg(feature = "macros")]
4239
pub use macros::apply;

src/rejection.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ impl CodecRejection {
119119
}
120120
}
121121

122-
/// Consumes the rejection and returns a pretty [`Message`] representing the error.
122+
/// Consumes the rejection and returns a pretty [`Message`] representing the
123+
/// error.
123124
///
124125
/// Useful for sending a detailed error message to the client, but not so much
125126
/// for local debugging.

src/response.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,15 @@ where
3636
mod axum_impls {
3737
use std::borrow::Cow;
3838

39-
use super::{ContentType, IntoCodecResponse};
40-
4139
use axum::{
4240
body::Bytes,
4341
http::StatusCode,
4442
response::{IntoResponse, Response},
4543
BoxError,
4644
};
4745

46+
use super::{ContentType, IntoCodecResponse};
47+
4848
impl<T, E> IntoCodecResponse for Result<T, E>
4949
where
5050
T: IntoCodecResponse,

src/routing.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,13 @@ use crate::{
77
CodecHandler, IntoCodecResponse,
88
};
99

10-
/// A light wrapper around axum's [`MethodRouter`](axum::routing::MethodRouter) (or [`ApiMethodRouter`](aide::axum::routing::ApiMethodRouter) if the `aide` feature is enabled).
10+
/// A light wrapper around axum's [`MethodRouter`](axum::routing::MethodRouter)
11+
/// (or [`ApiMethodRouter`](aide::axum::routing::ApiMethodRouter) if the `aide`
12+
/// feature is enabled).
1113
///
12-
/// However, responses are expected to be [`IntoCodecResponse`] (instead of [`IntoResponse`](axum::response::IntoResponse)), as they are automatically converted to the appropriate response type when appropriate.
14+
/// However, responses are expected to be [`IntoCodecResponse`] (instead of
15+
/// [`IntoResponse`](axum::response::IntoResponse)), as they are automatically
16+
/// converted to the appropriate response type when appropriate.
1317
pub struct MethodRouter<S = (), E = Infallible> {
1418
#[cfg(not(feature = "aide"))]
1519
inner: routing::MethodRouter<S, E>,
@@ -127,12 +131,19 @@ where
127131
S: Clone + Send + Sync + 'static,
128132
{
129133
method_router_chain_method!(delete, delete_with);
134+
130135
method_router_chain_method!(get, get_with);
136+
131137
method_router_chain_method!(head, head_with);
138+
132139
method_router_chain_method!(options, options_with);
140+
133141
method_router_chain_method!(patch, patch_with);
142+
134143
method_router_chain_method!(post, post_with);
144+
135145
method_router_chain_method!(put, put_with);
146+
136147
method_router_chain_method!(trace, trace_with);
137148
}
138149

0 commit comments

Comments
 (0)