Skip to content

Commit

Permalink
clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
sunli829 committed Sep 2, 2024
1 parent 810b6b6 commit 6efdf17
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ edition = "2021"
newline_style = "unix"
# comments
normalize_comments = true
#wrap_comments=true
wrap_comments = true
format_code_in_doc_comments = true
# imports
imports_granularity = "Crate"
Expand Down
64 changes: 32 additions & 32 deletions poem-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,14 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
{
let (parts, body) = request.into_parts();
let mut resp = Response::default().set_content_type(T::CONTENT_TYPES[0]);
let incoming_encoding =
match get_incoming_encodings(&parts.headers, &self.accept_compressed) {
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let incoming_encoding = match get_incoming_encodings(&parts.headers, self.accept_compressed)
{
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let mut stream = create_decode_request_body(self.codec.decoder(), body, incoming_encoding);

let res = match stream.next().await {
Expand Down Expand Up @@ -88,14 +88,14 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
{
let (parts, body) = request.into_parts();
let mut resp = Response::default().set_content_type(T::CONTENT_TYPES[0]);
let incoming_encoding =
match get_incoming_encodings(&parts.headers, &self.accept_compressed) {
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let incoming_encoding = match get_incoming_encodings(&parts.headers, self.accept_compressed)
{
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let stream = create_decode_request_body(self.codec.decoder(), body, incoming_encoding);

let res = service
Expand Down Expand Up @@ -132,14 +132,14 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
{
let (parts, body) = request.into_parts();
let mut resp = Response::default().set_content_type(T::CONTENT_TYPES[0]);
let incoming_encoding =
match get_incoming_encodings(&parts.headers, &self.accept_compressed) {
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let incoming_encoding = match get_incoming_encodings(&parts.headers, self.accept_compressed)
{
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let mut stream = create_decode_request_body(self.codec.decoder(), body, incoming_encoding);

let res = match stream.next().await {
Expand Down Expand Up @@ -179,14 +179,14 @@ impl<'a, T: Codec> GrpcServer<'a, T> {
{
let (parts, body) = request.into_parts();
let mut resp = Response::default().set_content_type(T::CONTENT_TYPES[0]);
let incoming_encoding =
match get_incoming_encodings(&parts.headers, &self.accept_compressed) {
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let incoming_encoding = match get_incoming_encodings(&parts.headers, self.accept_compressed)
{
Ok(incoming_encoding) => incoming_encoding,
Err(status) => {
resp.headers_mut().extend(status.to_headers());
return resp;
}
};
let stream = create_decode_request_body(self.codec.decoder(), body, incoming_encoding);

let res = service
Expand Down
46 changes: 23 additions & 23 deletions poem-openapi/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,65 +95,65 @@ impl<T> Default for ExtractParamOptions<T> {
/// - **Path&lt;T: Type>**
///
/// Extract the parameters in the request path into
/// [`Path`](crate::param::Path).
/// [`Path`](crate::param::Path).
///
/// - **Query&lt;T: Type>**
///
/// Extract the parameters in the query string into
/// [`Query`](crate::param::Query).
/// [`Query`](crate::param::Query).
///
/// - **Header&lt;T: Type>**
///
/// Extract the parameters in the request header into
/// [`Header`](crate::param::Header).
/// [`Header`](crate::param::Header).
///
/// - **Cookie&lt;T: Type>**
///
/// Extract the parameters in the cookie into
/// [`Cookie`](crate::param::Cookie).
/// [`Cookie`](crate::param::Cookie).
///
/// - **CookiePrivate&lt;T: Type>**
///
/// Extract the parameters in the private cookie into
/// [`CookiePrivate`](crate::param::CookiePrivate).
/// [`CookiePrivate`](crate::param::CookiePrivate).
///
/// - **CookieSigned&lt;T: Type>**
///
/// Extract the parameters in the signed cookie into
/// [`CookieSigned`](crate::param::CookieSigned).
/// [`CookieSigned`](crate::param::CookieSigned).
///
/// - **Binary&lt;T>**
///
/// Extract the request body as binary into
/// [`Binary`](crate::payload::Binary).
/// Extract the request body as binary into
/// [`Binary`](crate::payload::Binary).
///
/// - **Json&lt;T>**
///
/// Parse the request body in `JSON` format into
/// [`Json`](crate::payload::Json).
/// Parse the request body in `JSON` format into
/// [`Json`](crate::payload::Json).
///
/// - **PlainText&lt;T>**
///
/// Extract the request body as utf8 string into
/// [`PlainText`](crate::payload::PlainText).
/// Extract the request body as utf8 string into
/// [`PlainText`](crate::payload::PlainText).
///
/// - **Any type derived from the [`ApiRequest`](crate::ApiRequest) macro**
///
/// Extract the complex request body derived from the `ApiRequest` macro.
/// Extract the complex request body derived from the `ApiRequest` macro.
///
/// - **Any type derived from the [`Multipart`](crate::Multipart) macro**
///
/// Extract the multipart object derived from the `Multipart` macro.
/// Extract the multipart object derived from the `Multipart` macro.
///
/// - **Any type derived from the [`SecurityScheme`](crate::SecurityScheme)
/// macro**
///
/// Extract the authentication value derived from the `SecurityScheme`
/// macro.
/// Extract the authentication value derived from the `SecurityScheme`
/// macro.
///
/// - **T: poem::FromRequest**
///
/// Use Poem's extractor.
/// Use Poem's extractor.
#[allow(unused_variables)]
pub trait ApiExtractor<'a>: Sized {
/// The type of API extractor.
Expand Down Expand Up @@ -250,24 +250,24 @@ impl<T: Payload> ResponseContent for T {
///
/// - **Binary&lt;T: Type>**
///
/// A binary response with content type `application/octet-stream`.
/// A binary response with content type `application/octet-stream`.
///
/// - **Json&lt;T: Type>**
///
/// A JSON response with content type `application/json`.
/// A JSON response with content type `application/json`.
///
/// - **PlainText&lt;T: Type>**
///
/// A utf8 string response with content type `text/plain`.
/// A utf8 string response with content type `text/plain`.
///
/// - **Attachment&lt;T: Type>**
///
/// A file download response, the content type is
/// `application/octet-stream`.
/// A file download response, the content type is
/// `application/octet-stream`.
///
/// - **Response&lt;T: Type>**
///
/// A response type use it to modify the status code and HTTP headers.
/// A response type use it to modify the status code and HTTP headers.
///
/// - **()**
///
Expand Down
3 changes: 3 additions & 0 deletions poem-openapi/tests/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,7 @@ async fn hidden() {

#[test]
fn issue_405() {
#[allow(dead_code)]
struct Api;

#[OpenApi]
Expand All @@ -963,11 +964,13 @@ fn issue_405() {
operation_id = "hello",
transform = "my_transformer"
)]
#[allow(dead_code)]
async fn index(&self) -> PlainText<String> {
PlainText("hello, world!".to_string())
}
}

#[allow(dead_code)]
fn my_transformer(ep: impl Endpoint) -> impl Endpoint {
ep.map_to_response()
}
Expand Down
10 changes: 10 additions & 0 deletions poem-openapi/tests/webhook.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use poem_openapi::{
#[tokio::test]
async fn name() {
#[Webhook]
#[allow(dead_code)]
trait MyWebhooks {
#[oai(name = "a", method = "post")]
fn test1(&self);
Expand All @@ -28,6 +29,7 @@ async fn name() {
#[tokio::test]
async fn method() {
#[Webhook]
#[allow(dead_code)]
trait MyWebhooks {
#[oai(method = "post")]
fn test1(&self);
Expand All @@ -43,6 +45,7 @@ async fn method() {
#[tokio::test]
async fn deprecated() {
#[Webhook]
#[allow(dead_code)]
trait MyWebhooks {
#[oai(method = "post")]
fn test1(&self);
Expand All @@ -65,6 +68,7 @@ async fn tags() {
}

#[Webhook(tag = "MyTags::A")]
#[allow(dead_code)]
trait MyWebhooks: Sync {
#[oai(method = "post", tag = "MyTags::B", tag = "MyTags::C")]
fn test1(&self);
Expand All @@ -83,6 +87,7 @@ async fn tags() {
#[tokio::test]
async fn operation_id() {
#[Webhook]
#[allow(dead_code)]
trait MyWebhooks {
#[oai(method = "post", operation_id = "a")]
fn test1(&self);
Expand All @@ -104,6 +109,7 @@ async fn operation_id() {
#[tokio::test]
async fn parameters() {
#[Webhook]
#[allow(dead_code)]
trait MyWebhooks {
#[oai(method = "post")]
fn test(&self, a: Query<i32>, b: Path<String>);
Expand Down Expand Up @@ -139,6 +145,7 @@ async fn request_body() {
#[Webhook]
trait MyWebhooks {
#[oai(method = "post")]
#[allow(dead_code)]
fn test(&self, req: Json<i32>);
}

Expand All @@ -160,6 +167,7 @@ async fn response() {
#[Webhook]
trait MyWebhooks {
#[oai(method = "post")]
#[allow(dead_code)]
fn test(&self) -> Json<i32>;
}

Expand All @@ -184,6 +192,7 @@ async fn create() {
#[Webhook]
trait MyWebhooks {
#[oai(method = "post")]
#[allow(dead_code)]
fn test(&self) -> Json<i32>;
}

Expand All @@ -198,6 +207,7 @@ async fn external_docs() {
method = "post",
external_docs = "https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md"
)]
#[allow(dead_code)]
fn test(&self);
}

Expand Down
Loading

0 comments on commit 6efdf17

Please sign in to comment.