mirror of
https://github.com/poem-web/poem.git
synced 2026-01-25 04:18:25 +00:00
clippy
This commit is contained in:
@@ -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"
|
||||
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
@@ -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 {
|
||||
@@ -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
|
||||
|
||||
@@ -95,65 +95,65 @@ impl<T> Default for ExtractParamOptions<T> {
|
||||
/// - **Path<T: Type>**
|
||||
///
|
||||
/// Extract the parameters in the request path into
|
||||
/// [`Path`](crate::param::Path).
|
||||
/// [`Path`](crate::param::Path).
|
||||
///
|
||||
/// - **Query<T: Type>**
|
||||
///
|
||||
/// Extract the parameters in the query string into
|
||||
/// [`Query`](crate::param::Query).
|
||||
/// [`Query`](crate::param::Query).
|
||||
///
|
||||
/// - **Header<T: Type>**
|
||||
///
|
||||
/// Extract the parameters in the request header into
|
||||
/// [`Header`](crate::param::Header).
|
||||
/// [`Header`](crate::param::Header).
|
||||
///
|
||||
/// - **Cookie<T: Type>**
|
||||
///
|
||||
/// Extract the parameters in the cookie into
|
||||
/// [`Cookie`](crate::param::Cookie).
|
||||
/// [`Cookie`](crate::param::Cookie).
|
||||
///
|
||||
/// - **CookiePrivate<T: Type>**
|
||||
///
|
||||
/// Extract the parameters in the private cookie into
|
||||
/// [`CookiePrivate`](crate::param::CookiePrivate).
|
||||
/// [`CookiePrivate`](crate::param::CookiePrivate).
|
||||
///
|
||||
/// - **CookieSigned<T: Type>**
|
||||
///
|
||||
/// Extract the parameters in the signed cookie into
|
||||
/// [`CookieSigned`](crate::param::CookieSigned).
|
||||
/// [`CookieSigned`](crate::param::CookieSigned).
|
||||
///
|
||||
/// - **Binary<T>**
|
||||
///
|
||||
/// Extract the request body as binary into
|
||||
/// [`Binary`](crate::payload::Binary).
|
||||
/// Extract the request body as binary into
|
||||
/// [`Binary`](crate::payload::Binary).
|
||||
///
|
||||
/// - **Json<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<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.
|
||||
@@ -250,24 +250,24 @@ impl<T: Payload> ResponseContent for T {
|
||||
///
|
||||
/// - **Binary<T: Type>**
|
||||
///
|
||||
/// A binary response with content type `application/octet-stream`.
|
||||
/// A binary response with content type `application/octet-stream`.
|
||||
///
|
||||
/// - **Json<T: Type>**
|
||||
///
|
||||
/// A JSON response with content type `application/json`.
|
||||
/// A JSON response with content type `application/json`.
|
||||
///
|
||||
/// - **PlainText<T: Type>**
|
||||
///
|
||||
/// A utf8 string response with content type `text/plain`.
|
||||
/// A utf8 string response with content type `text/plain`.
|
||||
///
|
||||
/// - **Attachment<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<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.
|
||||
///
|
||||
/// - **()**
|
||||
///
|
||||
|
||||
@@ -953,6 +953,7 @@ async fn hidden() {
|
||||
|
||||
#[test]
|
||||
fn issue_405() {
|
||||
#[allow(dead_code)]
|
||||
struct Api;
|
||||
|
||||
#[OpenApi]
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
@@ -28,6 +29,7 @@ async fn name() {
|
||||
#[tokio::test]
|
||||
async fn method() {
|
||||
#[Webhook]
|
||||
#[allow(dead_code)]
|
||||
trait MyWebhooks {
|
||||
#[oai(method = "post")]
|
||||
fn test1(&self);
|
||||
@@ -43,6 +45,7 @@ async fn method() {
|
||||
#[tokio::test]
|
||||
async fn deprecated() {
|
||||
#[Webhook]
|
||||
#[allow(dead_code)]
|
||||
trait MyWebhooks {
|
||||
#[oai(method = "post")]
|
||||
fn test1(&self);
|
||||
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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>);
|
||||
@@ -139,6 +145,7 @@ async fn request_body() {
|
||||
#[Webhook]
|
||||
trait MyWebhooks {
|
||||
#[oai(method = "post")]
|
||||
#[allow(dead_code)]
|
||||
fn test(&self, req: Json<i32>);
|
||||
}
|
||||
|
||||
@@ -160,6 +167,7 @@ async fn response() {
|
||||
#[Webhook]
|
||||
trait MyWebhooks {
|
||||
#[oai(method = "post")]
|
||||
#[allow(dead_code)]
|
||||
fn test(&self) -> Json<i32>;
|
||||
}
|
||||
|
||||
@@ -184,6 +192,7 @@ async fn create() {
|
||||
#[Webhook]
|
||||
trait MyWebhooks {
|
||||
#[oai(method = "post")]
|
||||
#[allow(dead_code)]
|
||||
fn test(&self) -> Json<i32>;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -117,8 +117,7 @@ impl RequestBody {
|
||||
///
|
||||
/// - **Option<T>**
|
||||
///
|
||||
/// Extracts `T` from the incoming request, returns [`None`] if it
|
||||
/// fails.
|
||||
/// Extracts `T` from the incoming request, returns [`None`] if it fails.
|
||||
///
|
||||
/// - **&Request**
|
||||
///
|
||||
@@ -177,28 +176,28 @@ impl RequestBody {
|
||||
/// Extracts the [`Json`] from the incoming request.
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **Xml<T>**
|
||||
///
|
||||
/// Extracts the [`Xml`] from the incoming request.
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **TempFile**
|
||||
///
|
||||
/// Extracts the [`TempFile`] from the incoming request.
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **Multipart**
|
||||
///
|
||||
/// Extracts the [`Multipart`] from the incoming request.
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **&CookieJar**
|
||||
///
|
||||
@@ -209,7 +208,7 @@ impl RequestBody {
|
||||
/// - **&Session**
|
||||
///
|
||||
/// Extracts the [`Session`](crate::session::Session) from the incoming
|
||||
/// request.
|
||||
/// request.
|
||||
///
|
||||
/// _Requires `CookieSession` or `RedisSession` middleware._
|
||||
///
|
||||
@@ -218,54 +217,53 @@ impl RequestBody {
|
||||
/// Extracts the [`Body`] from the incoming request.
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **String**
|
||||
///
|
||||
/// Extracts the body from the incoming request and parse it into utf8
|
||||
/// [`String`].
|
||||
/// [`String`].
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **Vec<u8>**
|
||||
///
|
||||
/// Extracts the body from the incoming request and collect it into
|
||||
/// [`Vec<u8>`].
|
||||
/// [`Vec<u8>`].
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **Bytes**
|
||||
///
|
||||
/// Extracts the body from the incoming request and collect it into
|
||||
/// [`Bytes`].
|
||||
/// [`Bytes`].
|
||||
///
|
||||
/// _This extractor will take over the requested body, so you should avoid
|
||||
/// using multiple extractors of this type in one handler._
|
||||
/// using multiple extractors of this type in one handler._
|
||||
///
|
||||
/// - **WebSocket**
|
||||
///
|
||||
/// Ready to accept a websocket [`WebSocket`](websocket::WebSocket)
|
||||
/// connection.
|
||||
/// connection.
|
||||
///
|
||||
/// - **Locale**
|
||||
///
|
||||
/// Extracts the [`Locale`](crate::i18n::Locale) from the incoming
|
||||
/// request.
|
||||
/// Extracts the [`Locale`](crate::i18n::Locale) from the incoming request.
|
||||
///
|
||||
/// - **StaticFileRequest**
|
||||
///
|
||||
/// Ready to accept a static file request
|
||||
/// [`StaticFileRequest`](static_file::StaticFileRequest).
|
||||
/// Ready to accept a static file request
|
||||
/// [`StaticFileRequest`](static_file::StaticFileRequest).
|
||||
///
|
||||
/// - **Accept**
|
||||
///
|
||||
/// Extracts the `Accept` header from the incoming request.
|
||||
/// Extracts the `Accept` header from the incoming request.
|
||||
///
|
||||
/// - **PathPattern**
|
||||
///
|
||||
/// Extracts the matched path pattern from the incoming request.
|
||||
/// Extracts the matched path pattern from the incoming request.
|
||||
///
|
||||
/// # Create your own extractor
|
||||
///
|
||||
@@ -347,44 +345,46 @@ pub trait FromRequest<'a>: Sized {
|
||||
/// - **&'static str**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to `text/plain`. The
|
||||
/// string is used as the body of the response.
|
||||
/// string is used as the body of the response.
|
||||
///
|
||||
/// - **String**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to `text/plain`. The
|
||||
/// string is used as the body of the response.
|
||||
/// string is used as the body of the response.
|
||||
///
|
||||
/// - **&'static [u8]**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to
|
||||
/// `application/octet-stream`. The slice is used as the body of the response.
|
||||
/// `application/octet-stream`. The slice is used as the body of the
|
||||
/// response.
|
||||
///
|
||||
/// - **Html<T>**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to `text/html`. `T` is
|
||||
/// used as the body of the response.
|
||||
/// used as the body of the response.
|
||||
///
|
||||
/// - **Json<T>**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to `application/json`. Use
|
||||
/// [`serde_json`](https://crates.io/crates/serde_json) to serialize `T` into a json string.
|
||||
/// [`serde_json`](https://crates.io/crates/serde_json) to serialize `T` into a json string.
|
||||
///
|
||||
///
|
||||
/// - **Xml<T>**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to `application/xml`. Use
|
||||
/// [`quick-xml`](https://crates.io/crates/quick-xml) to serialize `T` into a xml string.
|
||||
/// [`quick-xml`](https://crates.io/crates/quick-xml) to serialize `T` into a xml string.
|
||||
///
|
||||
/// - **Bytes**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to
|
||||
/// `application/octet-stream`. The bytes is used as the body of the response.
|
||||
/// `application/octet-stream`. The bytes is used as the body of the
|
||||
/// response.
|
||||
///
|
||||
/// - **Vec<u8>**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to
|
||||
/// `application/octet-stream`. The vector’s data is used as the body of the
|
||||
/// response.
|
||||
/// `application/octet-stream`. The vector’s data is used as the body of the
|
||||
/// response.
|
||||
///
|
||||
/// - **Body**
|
||||
///
|
||||
@@ -393,7 +393,7 @@ pub trait FromRequest<'a>: Sized {
|
||||
/// - **StatusCode**
|
||||
///
|
||||
/// Sets the status to the specified status code [`StatusCode`] with an empty
|
||||
/// body.
|
||||
/// body.
|
||||
///
|
||||
/// - **(StatusCode, T)**
|
||||
///
|
||||
@@ -402,7 +402,7 @@ pub trait FromRequest<'a>: Sized {
|
||||
/// - **(StatusCode, HeaderMap, T)**
|
||||
///
|
||||
/// Convert `T` to response and set the specified status code [`StatusCode`],
|
||||
/// and then merge the specified [`HeaderMap`].
|
||||
/// and then merge the specified [`HeaderMap`].
|
||||
///
|
||||
/// - **Response**
|
||||
///
|
||||
@@ -411,14 +411,14 @@ pub trait FromRequest<'a>: Sized {
|
||||
/// - **Compress<T>**
|
||||
///
|
||||
/// Call `T::into_response` to get the response, then compress the response
|
||||
/// body with the specified algorithm, and set the correct `Content-Encoding`
|
||||
/// header.
|
||||
/// body with the specified algorithm, and set the correct `Content-Encoding`
|
||||
/// header.
|
||||
///
|
||||
/// - **SSE**
|
||||
///
|
||||
/// Sets the status to `OK` and the `Content-Type` to `text/event-stream`
|
||||
/// with an event stream body. Use the [`SSE::new`](sse::SSE::new) function to
|
||||
/// create it.
|
||||
/// Sets the status to `OK` and the `Content-Type` to `text/event-stream`
|
||||
/// with an event stream body. Use the [`SSE::new`](sse::SSE::new) function
|
||||
/// to create it.
|
||||
///
|
||||
/// # Create you own response
|
||||
///
|
||||
|
||||
Reference in New Issue
Block a user