diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 1e72a35a2..c9215df98 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: - { name: Linux, os: ubuntu-latest } - { name: macOS, os: macos-latest } version: - - 1.79 + - 1.85 name: http check @ ${{ matrix.target.name }} - ${{ matrix.version }} runs-on: ${{ matrix.target.os }} @@ -98,7 +98,7 @@ jobs: - { name: Linux, os: ubuntu-latest } - { name: macOS, os: macos-latest } version: - - 1.79 + - 1.85 name: client check @ ${{ matrix.target.name }} - ${{ matrix.version }} runs-on: ${{ matrix.target.os }} diff --git a/README.md b/README.md index b80b59eaa..84c7fdfbc 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,7 @@ # Minimum Supported Rust Version -The latest release of the crate supports 1.79 and above rust versions. +The latest release of the crate supports 1.85 and above rust versions. **[⬆️ Back to Top](#xitca-web)** diff --git a/codegen/CHANGES.md b/codegen/CHANGES.md index 818a8030f..6d6349bdf 100644 --- a/codegen/CHANGES.md +++ b/codegen/CHANGES.md @@ -1,9 +1,10 @@ # unreleased 0.4.0 -## Fix -- fix `xitca_web::WebContext` parsing when generic body type is presented. - ## Change - macro is refactored to target xitca-web `0.7.0` +- bump MSRV to `1.85` and Rust edition 2024 + +## Fix +- fix `xitca_web::WebContext` parsing when generic body type is presented. # 0.3.1 ## Fix diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml index 48d92dd13..52b37c4e5 100644 --- a/codegen/Cargo.toml +++ b/codegen/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xitca-codegen" version = "0.4.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" description = "proc macro for xitca" repository = "https://github.com/HFQR/xitca-web" diff --git a/codegen/src/error.rs b/codegen/src/error.rs index f9fd74064..8ba5c265e 100644 --- a/codegen/src/error.rs +++ b/codegen/src/error.rs @@ -1,6 +1,6 @@ use proc_macro::TokenStream; use quote::quote; -use syn::{spanned::Spanned, Error, ItemImpl, Type}; +use syn::{Error, ItemImpl, Type, spanned::Spanned}; pub(crate) fn error(_: TokenStream, item: ItemImpl) -> Result { let Type::Path(ref err_ty) = *item.self_ty else { diff --git a/codegen/src/lib.rs b/codegen/src/lib.rs index d9b38b50a..574889775 100644 --- a/codegen/src/lib.rs +++ b/codegen/src/lib.rs @@ -4,7 +4,7 @@ mod service; mod state; use proc_macro::TokenStream; -use syn::{spanned::Spanned, Error, ImplItem, ImplItemFn}; +use syn::{Error, ImplItem, ImplItemFn, spanned::Spanned}; #[proc_macro_derive(State, attributes(borrow))] pub fn state_impl(item: TokenStream) -> TokenStream { diff --git a/codegen/src/route.rs b/codegen/src/route.rs index f8187ce0b..684363d5a 100644 --- a/codegen/src/route.rs +++ b/codegen/src/route.rs @@ -1,10 +1,10 @@ use proc_macro::TokenStream; use quote::quote; use syn::{ + Error, Expr, FnArg, GenericArgument, ItemFn, PathArguments, Type, parse::{Parse, ParseStream}, punctuated::Punctuated, spanned::Spanned, - Error, Expr, FnArg, GenericArgument, ItemFn, PathArguments, Type, }; pub(crate) fn route(attr: Args, input: ItemFn) -> Result { @@ -105,7 +105,7 @@ pub(crate) fn route(attr: Args, input: ItemFn) -> Result { return Err(Error::new(path.span(), format!("expect {ident}<_>"))); }; match arg.args.last() { - Some(GenericArgument::Type(ref ty)) => { + Some(GenericArgument::Type(ty)) => { state.push(State::Partial(ty)); } _ => return Err(Error::new(ty.span(), "expect state type.")), @@ -115,6 +115,7 @@ pub(crate) fn route(attr: Args, input: ItemFn) -> Result { let PathArguments::AngleBracketed(ref arg) = path.arguments else { return Err(Error::new(path.span(), format!("expect &{ident}<'_, _>"))); }; + let mut args = arg.args.iter(); match args.next() { @@ -123,7 +124,7 @@ pub(crate) fn route(attr: Args, input: ItemFn) -> Result { } match args.next() { - Some(GenericArgument::Type(ref ty)) => { + Some(GenericArgument::Type(ty)) => { state.push(State::Full(ty)); } None => { diff --git a/codegen/src/service.rs b/codegen/src/service.rs index 227e952c3..b835634e0 100644 --- a/codegen/src/service.rs +++ b/codegen/src/service.rs @@ -2,11 +2,11 @@ use proc_macro::TokenStream; use quote::quote; use syn::{ __private::{Span, TokenStream2}, + Error, FnArg, GenericArgument, GenericParam, Ident, ImplItemFn, ItemImpl, Pat, PatIdent, PathArguments, ReturnType, + Stmt, Type, TypePath, WhereClause, punctuated::Punctuated, spanned::Spanned, token::Comma, - Error, FnArg, GenericArgument, GenericParam, Ident, ImplItemFn, ItemImpl, Pat, PatIdent, PathArguments, ReturnType, - Stmt, Type, TypePath, WhereClause, }; use crate::find_async_method; @@ -184,7 +184,7 @@ impl<'a> BuilderImpl<'a> { return Err(Error::new( recv.span(), "new_service method does not accept Self as receiver", - )) + )); } FnArg::Typed(ty) => match (ty.pat.as_ref(), ty.ty.as_ref()) { (Pat::Wild(_), Type::Reference(ty_ref)) if ty_ref.mutability.is_none() => { @@ -197,7 +197,7 @@ impl<'a> BuilderImpl<'a> { return Err(Error::new( ty.span(), "new_service must receive ServiceFactory type as immutable reference", - )) + )); } }, }; @@ -212,7 +212,7 @@ impl<'a> BuilderImpl<'a> { return Err(Error::new( recv.span(), "new_service method does not accept Self as receiver", - )) + )); } FnArg::Typed(ty) => match ty.pat.as_ref() { Pat::Wild(_) => (default_pat_ident("_service"), &*ty.ty), @@ -221,7 +221,7 @@ impl<'a> BuilderImpl<'a> { return Err(Error::new( ty.span(), "new_service method must use 'arg: Arg' as second function argument", - )) + )); } }, }; @@ -271,7 +271,7 @@ impl<'a> CallImpl<'a> { ) })? { FnArg::Receiver(recv) => { - return Err(Error::new(recv.span(), "call method does not accept Self as receiver")) + return Err(Error::new(recv.span(), "call method does not accept Self as receiver")); } FnArg::Typed(ty) => match ty.pat.as_ref() { Pat::Wild(_) => (default_pat_ident("_req"), &*ty.ty), @@ -280,7 +280,7 @@ impl<'a> CallImpl<'a> { return Err(Error::new( ty.span(), "call method must use 'req: Req' as second function argument", - )) + )); } }, }; diff --git a/http-ws/Cargo.toml b/http-ws/Cargo.toml index 02c11665d..ac8d53bab 100644 --- a/http-ws/Cargo.toml +++ b/http-ws/Cargo.toml @@ -21,7 +21,7 @@ base64 = { version = "0.22.0", default-features = false } bytes = "1.4" futures-core = { version = "0.3.25", default-features = false } http = "1" -rand = { version = "0.8.5" } +rand = { version = "0.9.0" } sha1 = "0.10" tracing = { version = "0.1.40", default-features = false } diff --git a/http/CHANGES.md b/http/CHANGES.md index 29593c349..d970b52ef 100644 --- a/http/CHANGES.md +++ b/http/CHANGES.md @@ -1,5 +1,6 @@ # unreleased 0.7.0 ## Change +- bump MSRV to `1.85` and Rust edition 2024 - update `xitca-service` to `0.3.0` # 0.6.0 diff --git a/http/Cargo.toml b/http/Cargo.toml index 12d89bf79..ba0b88d9f 100644 --- a/http/Cargo.toml +++ b/http/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xitca-http" version = "0.7.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" description = "http library for xitca" repository = "https://github.com/HFQR/xitca-web" @@ -38,7 +38,7 @@ router = ["xitca-router"] [dependencies] xitca-io = "0.4.0" -xitca-service = { version = "0.3.0", features = ["alloc", "std"] } +xitca-service = { version = "0.3.0", features = ["alloc"] } xitca-unsafe-collection = { version = "0.2.0", features = ["bytes"] } futures-core = "0.3.17" diff --git a/http/benches/h1_decode.rs b/http/benches/h1_decode.rs index 9f59c5253..f780f85a1 100644 --- a/http/benches/h1_decode.rs +++ b/http/benches/h1_decode.rs @@ -1,11 +1,11 @@ use std::time::SystemTime; -use criterion::{black_box, criterion_group, criterion_main, Criterion}; +use criterion::{Criterion, black_box, criterion_group, criterion_main}; use httpdate::HttpDate; use tokio::time::Instant; use xitca_http::{ bytes::BytesMut, - date::{DateTime, DATE_VALUE_LENGTH}, + date::{DATE_VALUE_LENGTH, DateTime}, h1::proto::context::Context, }; diff --git a/http/src/builder.rs b/http/src/builder.rs index a3c58925b..c5bd8417d 100644 --- a/http/src/builder.rs +++ b/http/src/builder.rs @@ -5,7 +5,7 @@ use xitca_service::Service; use super::{ body::RequestBody, - config::{HttpServiceConfig, DEFAULT_HEADER_LIMIT, DEFAULT_READ_BUF_LIMIT, DEFAULT_WRITE_BUF_LIMIT}, + config::{DEFAULT_HEADER_LIMIT, DEFAULT_READ_BUF_LIMIT, DEFAULT_WRITE_BUF_LIMIT, HttpServiceConfig}, service::HttpService, tls, }; diff --git a/http/src/date.rs b/http/src/date.rs index b032bb318..6088bbe01 100644 --- a/http/src/date.rs +++ b/http/src/date.rs @@ -11,7 +11,7 @@ use std::{ use httpdate::HttpDate; use tokio::{ task::JoinHandle, - time::{interval, Instant}, + time::{Instant, interval}, }; /// Trait for getting current date/time. diff --git a/http/src/h1/body.rs b/http/src/h1/body.rs index 8ffa07630..cd4016a3d 100644 --- a/http/src/h1/body.rs +++ b/http/src/h1/body.rs @@ -1,6 +1,6 @@ use core::{ cell::{RefCell, RefMut}, - future::{poll_fn, Future}, + future::{Future, poll_fn}, ops::DerefMut, pin::Pin, task::{Context, Poll, Waker}, diff --git a/http/src/h1/builder.rs b/http/src/h1/builder.rs index d58170315..df9a4320d 100644 --- a/http/src/h1/builder.rs +++ b/http/src/h1/builder.rs @@ -2,7 +2,7 @@ use core::fmt; use xitca_service::Service; -use crate::builder::{marker, HttpServiceBuilder}; +use crate::builder::{HttpServiceBuilder, marker}; use super::service::H1Service; diff --git a/http/src/h1/dispatcher.rs b/http/src/h1/dispatcher.rs index 402e8b45f..da47bd456 100644 --- a/http/src/h1/dispatcher.rs +++ b/http/src/h1/dispatcher.rs @@ -1,9 +1,9 @@ use core::{ convert::Infallible, - future::{pending, poll_fn, Future}, + future::{Future, pending, poll_fn}, marker::PhantomData, net::SocketAddr, - pin::{pin, Pin}, + pin::{Pin, pin}, time::Duration, }; @@ -25,8 +25,8 @@ use crate::{ error::Error, }, http::{ - response::{Parts, Response}, StatusCode, + response::{Parts, Response}, }, util::{ buffered::{BufferedIo, ListWriteBuf, ReadBuf, WriteBuf}, diff --git a/http/src/h1/dispatcher_unreal.rs b/http/src/h1/dispatcher_unreal.rs index 48ef77f03..93c1cc815 100644 --- a/http/src/h1/dispatcher_unreal.rs +++ b/http/src/h1/dispatcher_unreal.rs @@ -9,7 +9,7 @@ use xitca_io::{ io::{AsyncIo, Interest}, net::TcpStream, }; -use xitca_service::{AsyncFn, Service}; +use xitca_service::Service; use xitca_unsafe_collection::bytes::read_buf; use crate::date::{DateTime, DateTimeHandle, DateTimeService}; @@ -107,7 +107,7 @@ impl Dispatcher { impl Service for Dispatcher where - F: for<'h, 'b> AsyncFn<(Request<'h, C>, Response<'h>), Output = Response<'h, 3>>, + F: for<'h, 'b> AsyncFn(Request<'h, C>, Response<'h>) -> Response<'h, 3>, { type Response = (); type Error = Error; @@ -154,7 +154,7 @@ where date: self.date.get(), }; - self.handler.call((req, res)).await; + (self.handler)(req, res).await; r_buf.advance(len); } diff --git a/http/src/h1/dispatcher_uring.rs b/http/src/h1/dispatcher_uring.rs index 2a49b42e1..2825da9e7 100644 --- a/http/src/h1/dispatcher_uring.rs +++ b/http/src/h1/dispatcher_uring.rs @@ -1,13 +1,13 @@ use core::{ cell::RefCell, fmt, - future::{poll_fn, Future}, + future::{Future, poll_fn}, marker::PhantomData, mem, net::SocketAddr, ops::{Deref, DerefMut}, - pin::{pin, Pin}, - task::{self, ready, Poll, Waker}, + pin::{Pin, pin}, + task::{self, Poll, Waker, ready}, }; use std::{io, net::Shutdown, rc::Rc}; @@ -17,7 +17,7 @@ use pin_project_lite::pin_project; use tracing::trace; use xitca_io::{ bytes::BytesMut, - io_uring::{write_all, AsyncBufRead, AsyncBufWrite, BoundedBuf}, + io_uring::{AsyncBufRead, AsyncBufWrite, BoundedBuf, write_all}, }; use xitca_service::Service; use xitca_unsafe_collection::futures::SelectOutput; @@ -28,12 +28,12 @@ use crate::{ config::HttpServiceConfig, date::DateTime, h1::{body::RequestBody, error::Error}, - http::{response::Response, StatusCode}, + http::{StatusCode, response::Response}, util::timer::{KeepAlive, Timeout}, }; use super::{ - dispatcher::{status_only, Timer}, + dispatcher::{Timer, status_only}, proto::{ codec::{ChunkResult, TransferCoding}, context::Context, diff --git a/http/src/h1/proto/buf_write.rs b/http/src/h1/proto/buf_write.rs index c56d45246..a68699093 100644 --- a/http/src/h1/proto/buf_write.rs +++ b/http/src/h1/proto/buf_write.rs @@ -3,7 +3,7 @@ use core::convert::Infallible; use std::io::Write; use crate::{ - bytes::{buf::Chain, Buf, BufMut, BufMutWriter, Bytes, BytesMut, EitherBuf}, + bytes::{Buf, BufMut, BufMutWriter, Bytes, BytesMut, EitherBuf, buf::Chain}, util::buffered::{BufWrite, ListWriteBuf, WriteBuf}, }; diff --git a/http/src/h1/proto/context.rs b/http/src/h1/proto/context.rs index 271b2e71a..1d0035f6f 100644 --- a/http/src/h1/proto/context.rs +++ b/http/src/h1/proto/context.rs @@ -1,6 +1,6 @@ use core::{mem, net::SocketAddr}; -use crate::http::{header::HeaderMap, Extensions}; +use crate::http::{Extensions, header::HeaderMap}; /// Context is connection specific struct contain states for processing. pub struct Context<'a, D, const HEADER_LIMIT: usize> { diff --git a/http/src/h1/proto/decode.rs b/http/src/h1/proto/decode.rs index 3695e7648..cd03ad75d 100644 --- a/http/src/h1/proto/decode.rs +++ b/http/src/h1/proto/decode.rs @@ -5,8 +5,8 @@ use httparse::Status; use crate::{ bytes::{Buf, Bytes, BytesMut}, http::{ - header::{HeaderMap, HeaderName, HeaderValue, CONNECTION, CONTENT_LENGTH, EXPECT, TRANSFER_ENCODING, UPGRADE}, Extension, Method, Request, RequestExt, Uri, Version, + header::{CONNECTION, CONTENT_LENGTH, EXPECT, HeaderMap, HeaderName, HeaderValue, TRANSFER_ENCODING, UPGRADE}, }, }; diff --git a/http/src/h1/proto/encode.rs b/http/src/h1/proto/encode.rs index 88fbf4894..09fd3e5b4 100644 --- a/http/src/h1/proto/encode.rs +++ b/http/src/h1/proto/encode.rs @@ -6,9 +6,9 @@ use crate::{ bytes::{Bytes, BytesMut}, date::DateTime, http::{ - header::{HeaderMap, CONNECTION, CONTENT_LENGTH, DATE, SET_COOKIE, TE, TRANSFER_ENCODING, UPGRADE}, - response::Parts, StatusCode, Version, + header::{CONNECTION, CONTENT_LENGTH, DATE, HeaderMap, SET_COOKIE, TE, TRANSFER_ENCODING, UPGRADE}, + response::Parts, }, }; diff --git a/http/src/h2/body.rs b/http/src/h2/body.rs index def2235b6..302d8663d 100644 --- a/http/src/h2/body.rs +++ b/http/src/h2/body.rs @@ -1,6 +1,6 @@ use core::{ pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use futures_core::stream::Stream; diff --git a/http/src/h2/builder.rs b/http/src/h2/builder.rs index 9d6aadb05..56dbf6ecb 100644 --- a/http/src/h2/builder.rs +++ b/http/src/h2/builder.rs @@ -2,7 +2,7 @@ use core::fmt; use xitca_service::Service; -use crate::builder::{marker, HttpServiceBuilder}; +use crate::builder::{HttpServiceBuilder, marker}; use super::service::H2Service; diff --git a/http/src/h2/mod.rs b/http/src/h2/mod.rs index 810324c0a..cf8e34561 100644 --- a/http/src/h2/mod.rs +++ b/http/src/h2/mod.rs @@ -14,4 +14,4 @@ pub use self::error::Error; pub use self::service::H2Service; #[cfg(feature = "io-uring")] -pub use self::proto::{run, RequestBody as RequestBodyV2, RequestBodySender}; +pub use self::proto::{RequestBody as RequestBodyV2, RequestBodySender, run}; diff --git a/http/src/h2/proto/dispatcher.rs b/http/src/h2/proto/dispatcher.rs index c7775d516..725f98fcc 100644 --- a/http/src/h2/proto/dispatcher.rs +++ b/http/src/h2/proto/dispatcher.rs @@ -1,16 +1,16 @@ use core::{ cmp, fmt, - future::{poll_fn, Future}, + future::{Future, poll_fn}, marker::PhantomData, net::SocketAddr, - pin::{pin, Pin}, - task::{ready, Context, Poll}, + pin::{Pin, pin}, + task::{Context, Poll, ready}, time::Duration, }; use ::h2::{ - server::{Connection, SendResponse}, Ping, PingPong, + server::{Connection, SendResponse}, }; use futures_core::stream::Stream; use tracing::trace; @@ -25,8 +25,8 @@ use crate::{ error::HttpServiceError, h2::{body::RequestBody, error::Error}, http::{ - header::{HeaderMap, HeaderName, HeaderValue, CONNECTION, CONTENT_LENGTH, DATE, TRAILER}, Extension, Request, RequestExt, Response, Version, + header::{CONNECTION, CONTENT_LENGTH, DATE, HeaderMap, HeaderName, HeaderValue, TRAILER}, }, util::{futures::Queue, timer::KeepAlive}, }; @@ -46,10 +46,8 @@ impl<'a, TlsSt, S, ReqB, ResB, BE> Dispatcher<'a, TlsSt, S, ReqB> where S: Service>, Response = Response>, S::Error: fmt::Debug, - ResB: Stream>, BE: fmt::Debug, - TlsSt: AsyncRead + AsyncWrite + Unpin, ReqB: From, { diff --git a/http/src/h2/proto/headers.rs b/http/src/h2/proto/headers.rs index a6ac5ff1f..d0a5cae75 100644 --- a/http/src/h2/proto/headers.rs +++ b/http/src/h2/proto/headers.rs @@ -7,10 +7,11 @@ use std::io::Cursor; use xitca_unsafe_collection::bytes::BytesStr; use crate::{ - bytes::{buf::Limit, BufMut, Bytes, BytesMut}, + bytes::{BufMut, Bytes, BytesMut, buf::Limit}, http::{ + HeaderMap, Method, StatusCode, Uri, header::{self, HeaderName}, - uri, HeaderMap, Method, StatusCode, Uri, + uri, }, }; diff --git a/http/src/h2/proto/hpack/header.rs b/http/src/h2/proto/hpack/header.rs index 7780fce9c..b2b150100 100644 --- a/http/src/h2/proto/hpack/header.rs +++ b/http/src/h2/proto/hpack/header.rs @@ -3,8 +3,8 @@ use xitca_unsafe_collection::bytes::BytesStr; use crate::{ bytes::Bytes, http::{ - header::{self, HeaderName, HeaderValue}, Method, StatusCode, + header::{self, HeaderName, HeaderValue}, }, }; diff --git a/http/src/h2/proto/mod.rs b/http/src/h2/proto/mod.rs index f573ad1fa..a1e83ff30 100644 --- a/http/src/h2/proto/mod.rs +++ b/http/src/h2/proto/mod.rs @@ -19,16 +19,16 @@ pub(crate) use dispatcher::Dispatcher; const HEADER_LEN: usize = 9; #[cfg(feature = "io-uring")] -pub use io_uring::{run, RequestBody, RequestBodySender}; +pub use io_uring::{RequestBody, RequestBodySender, run}; #[cfg(feature = "io-uring")] mod io_uring { use core::{ cell::RefCell, fmt, - future::{poll_fn, Future}, + future::{Future, poll_fn}, mem, - pin::{pin, Pin}, + pin::{Pin, pin}, task::{Context, Poll, Waker}, }; @@ -41,7 +41,7 @@ mod io_uring { use tracing::error; use xitca_io::{ bytes::{Buf, BufMut, BytesMut}, - io_uring::{write_all, AsyncBufRead, AsyncBufWrite, BoundedBuf}, + io_uring::{AsyncBufRead, AsyncBufWrite, BoundedBuf, write_all}, }; use xitca_service::Service; use xitca_unsafe_collection::futures::{Select, SelectOutput}; @@ -50,7 +50,7 @@ mod io_uring { body::BodySize, bytes::Bytes, error::BodyError, - http::{header::CONTENT_LENGTH, HeaderMap, Request, RequestExt, Response, Version}, + http::{HeaderMap, Request, RequestExt, Response, Version, header::CONTENT_LENGTH}, util::futures::Queue, }; @@ -391,42 +391,44 @@ mod io_uring { } loop { - let state = poll_fn(|cx| loop { - match rx.poll_recv(cx) { - Poll::Ready(Some(msg)) => { - match msg { - Message::Head(headers) => { - let mut buf = (&mut write_buf).limit(4096); - headers.encode(&mut encoder, &mut buf); - } - Message::Data(mut data) => { - data.encode_chunk(&mut write_buf); - } - Message::Trailer(headers) => { - let mut buf = (&mut write_buf).limit(4096); - headers.encode(&mut encoder, &mut buf); - } - Message::Reset(id, reason) => { - let reset = Reset::new(id, reason); - reset.encode(&mut write_buf); - } - Message::WindowUpdate(id, size) => { - debug_assert!(size > 0, "window update size not be 0"); - // TODO: batch window update - let update = WindowUpdate::new(0.into(), size as _); - update.encode(&mut write_buf); - let update = WindowUpdate::new(id, size as _); - update.encode(&mut write_buf); - } - Message::Settings => { - let setting = Settings::ack(); - setting.encode(&mut write_buf); - } - }; + let state = poll_fn(|cx| { + loop { + match rx.poll_recv(cx) { + Poll::Ready(Some(msg)) => { + match msg { + Message::Head(headers) => { + let mut buf = (&mut write_buf).limit(4096); + headers.encode(&mut encoder, &mut buf); + } + Message::Data(mut data) => { + data.encode_chunk(&mut write_buf); + } + Message::Trailer(headers) => { + let mut buf = (&mut write_buf).limit(4096); + headers.encode(&mut encoder, &mut buf); + } + Message::Reset(id, reason) => { + let reset = Reset::new(id, reason); + reset.encode(&mut write_buf); + } + Message::WindowUpdate(id, size) => { + debug_assert!(size > 0, "window update size not be 0"); + // TODO: batch window update + let update = WindowUpdate::new(0.into(), size as _); + update.encode(&mut write_buf); + let update = WindowUpdate::new(id, size as _); + update.encode(&mut write_buf); + } + Message::Settings => { + let setting = Settings::ack(); + setting.encode(&mut write_buf); + } + }; + } + Poll::Pending if write_buf.is_empty() => return Poll::Pending, + Poll::Pending => return Poll::Ready(State::Write), + Poll::Ready(None) => return Poll::Ready(State::WriteEof), } - Poll::Pending if write_buf.is_empty() => return Poll::Pending, - Poll::Pending => return Poll::Ready(State::Write), - Poll::Ready(None) => return Poll::Ready(State::WriteEof), } }) .await; diff --git a/http/src/h2/service.rs b/http/src/h2/service.rs index 0acdfa1bb..fbd633072 100644 --- a/http/src/h2/service.rs +++ b/http/src/h2/service.rs @@ -17,27 +17,15 @@ use super::{body::RequestBody, proto::Dispatcher}; pub type H2Service = HttpService; -impl< - St, - S, - ResB, - BE, - A, - TlsSt, - const HEADER_LIMIT: usize, - const READ_BUF_LIMIT: usize, - const WRITE_BUF_LIMIT: usize, - > Service<(St, SocketAddr)> for H2Service +impl + Service<(St, SocketAddr)> for H2Service where S: Service>, Response = Response>, S::Error: fmt::Debug, - A: Service, St: AsyncIo, TlsSt: AsyncIo, - HttpServiceError: From, - ResB: Stream>, BE: fmt::Debug, { @@ -140,7 +128,6 @@ mod io_uring { A::Response: AsyncBufRead + AsyncBufWrite + 'static, B: Stream>, HttpServiceError: From, - S::Error: fmt::Debug, BE: fmt::Debug, { diff --git a/http/src/h3/proto/dispatcher.rs b/http/src/h3/proto/dispatcher.rs index 9aa3a2bc9..4fd863450 100644 --- a/http/src/h3/proto/dispatcher.rs +++ b/http/src/h3/proto/dispatcher.rs @@ -1,6 +1,6 @@ use core::{ fmt, - future::{poll_fn, Future}, + future::{Future, poll_fn}, marker::PhantomData, net::SocketAddr, pin::pin, @@ -35,10 +35,8 @@ impl<'a, S, ReqB, ResB, BE> Dispatcher<'a, S, ReqB> where S: Service>, Response = Response>, S::Error: fmt::Debug, - ResB: Stream>, BE: fmt::Debug, - ReqB: From, { pub(crate) fn new(io: QuicStream, addr: SocketAddr, service: &'a S) -> Self { diff --git a/http/src/h3/service.rs b/http/src/h3/service.rs index 1678a9bcf..2727efef0 100644 --- a/http/src/h3/service.rs +++ b/http/src/h3/service.rs @@ -2,7 +2,7 @@ use core::{fmt, net::SocketAddr}; use futures_core::Stream; use xitca_io::net::QuicStream; -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; use crate::{ bytes::Bytes, @@ -28,7 +28,6 @@ impl Service<(QuicStream, SocketAddr)> for H3Service where S: Service>, Response = Response>, S::Error: fmt::Debug, - ResB: Stream>, BE: fmt::Debug, { diff --git a/http/src/service.rs b/http/src/service.rs index c3cd1127c..703a814bf 100644 --- a/http/src/service.rs +++ b/http/src/service.rs @@ -5,7 +5,7 @@ use xitca_io::{ io::AsyncIo, net::{Stream as ServerStream, TcpStream}, }; -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; use super::{ body::RequestBody, diff --git a/http/src/util/buffered/buffer.rs b/http/src/util/buffered/buffer.rs index 132e9a40b..25e4ac146 100644 --- a/http/src/util/buffered/buffer.rs +++ b/http/src/util/buffered/buffer.rs @@ -8,7 +8,7 @@ use std::io; use tracing::trace; use xitca_io::bytes::{Buf, BytesMut}; -use xitca_unsafe_collection::bytes::{read_buf, BufList, ChunkVectoredUninit}; +use xitca_unsafe_collection::bytes::{BufList, ChunkVectoredUninit, read_buf}; pub use xitca_io::bytes::{BufInterest, BufRead, BufWrite}; diff --git a/http/src/util/buffered/buffered_io.rs b/http/src/util/buffered/buffered_io.rs index cd8ca6810..77912f111 100644 --- a/http/src/util/buffered/buffered_io.rs +++ b/http/src/util/buffered/buffered_io.rs @@ -1,5 +1,5 @@ use core::{ - future::{poll_fn, Future}, + future::{Future, poll_fn}, pin::Pin, }; diff --git a/http/src/util/middleware/catch_unwind.rs b/http/src/util/middleware/catch_unwind.rs index 15b57b296..56e897c34 100644 --- a/http/src/util/middleware/catch_unwind.rs +++ b/http/src/util/middleware/catch_unwind.rs @@ -2,7 +2,7 @@ use core::any::Any; -use xitca_service::{pipeline::PipelineE, Service}; +use xitca_service::{Service, pipeline::PipelineE}; /// builder for middleware catching panic and unwind it to [`CatchUnwindError`]. pub struct CatchUnwind; diff --git a/http/src/util/middleware/context.rs b/http/src/util/middleware/context.rs index 6507deb59..0a160a4e1 100644 --- a/http/src/util/middleware/context.rs +++ b/http/src/util/middleware/context.rs @@ -222,7 +222,7 @@ mod router_impl { mod test { use std::convert::Infallible; - use xitca_service::{fn_service, ServiceExt}; + use xitca_service::{ServiceExt, fn_service}; use xitca_unsafe_collection::futures::NowOrPanic; use crate::http::{Request, Response}; @@ -269,7 +269,7 @@ mod test { fn test_state_in_router() { use crate::{ http::RequestExt, - util::service::{route::get, Router}, + util::service::{Router, route::get}, }; async fn handler(req: Context<'_, Request>, String>) -> Result, Infallible> { diff --git a/http/src/util/middleware/extension.rs b/http/src/util/middleware/extension.rs index 7bd1e974a..54c81e9e4 100644 --- a/http/src/util/middleware/extension.rs +++ b/http/src/util/middleware/extension.rs @@ -1,4 +1,4 @@ -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; use crate::http::{BorrowReqMut, Extensions}; @@ -83,7 +83,7 @@ where #[cfg(test)] mod test { - use xitca_service::{fn_service, ServiceExt}; + use xitca_service::{ServiceExt, fn_service}; use xitca_unsafe_collection::futures::NowOrPanic; use crate::http::Request; diff --git a/http/src/util/middleware/logger.rs b/http/src/util/middleware/logger.rs index 2776d2d5b..3995c6bad 100644 --- a/http/src/util/middleware/logger.rs +++ b/http/src/util/middleware/logger.rs @@ -40,10 +40,10 @@ impl Service> for Logger { mod service { use std::error; - use tracing::{event, span, Instrument}; + use tracing::{Instrument, event, span}; use xitca_service::ready::ReadyService; - use crate::http::{header::HeaderMap, BorrowReq, Method, Uri}; + use crate::http::{BorrowReq, Method, Uri, header::HeaderMap}; use super::*; diff --git a/http/src/util/middleware/socket_config.rs b/http/src/util/middleware/socket_config.rs index 238212d9f..ff024ca9d 100644 --- a/http/src/util/middleware/socket_config.rs +++ b/http/src/util/middleware/socket_config.rs @@ -6,7 +6,7 @@ use socket2::{SockRef, TcpKeepalive}; use tracing::warn; use xitca_io::net::{Stream as ServerStream, TcpStream}; -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; #[cfg(unix)] use xitca_io::net::UnixStream; diff --git a/http/src/util/service/handler.rs b/http/src/util/service/handler.rs index f67b9e4fa..9d9372909 100644 --- a/http/src/util/service/handler.rs +++ b/http/src/util/service/handler.rs @@ -1,8 +1,10 @@ //! high level async function service with "variadic generic" ish. +#![allow(non_snake_case)] + use core::{convert::Infallible, future::Future, marker::PhantomData, net::SocketAddr}; -use xitca_service::{pipeline::PipelineE, AsyncFn, Service}; +use xitca_service::{Service, pipeline::PipelineE}; use crate::http::{BorrowReq, Extensions, HeaderMap, Method, Request, RequestExt, Uri}; @@ -13,7 +15,7 @@ use crate::http::{BorrowReq, Extensions, HeaderMap, Method, Request, RequestExt, /// output type. pub fn handler_service(func: F) -> HandlerService where - F: AsyncFn + Clone, + F: AsyncFn2 + Clone, { HandlerService::new(func) } @@ -61,8 +63,8 @@ where // for borrowed extractors, `T` is the `'static` version of the extractors T: FromRequest<'static, Req>, // just to assist type inference to pinpoint `T` - F: AsyncFn, - F: for<'a> AsyncFn, Output = O>, + F: AsyncFn2, + F: for<'a> AsyncFn2, Output = O>, O: Responder, T::Error: From, { @@ -297,6 +299,46 @@ impl<'a, B> FromRequest<'a, Request>> for &'a SocketAddr { } } +/// helper trait flatting tuple of arguments. +/// +/// [`FromRequest`] trait extract a tuple of (type1, type2, type3, ..) from request type. this trait would destruct the tuple +/// handling over it to an async function use them as arguments. +pub trait AsyncFn2 { + type Output; + type Future: Future; + + fn call(&self, arg: Arg) -> Self::Future; +} + +macro_rules! async_fn_impl { + ($($arg: ident),*) => { + impl AsyncFn2<($($arg,)*)> for Func + where + Func: Fn($($arg),*) -> Fut, + Fut: Future, + { + type Output = Fut::Output; + type Future = Fut; + + #[inline] + fn call(&self, ($($arg,)*): ($($arg,)*)) -> Self::Future { + self($($arg,)*) + } + } + } +} + +async_fn_impl! {} +async_fn_impl! { A } +async_fn_impl! { A, B } +async_fn_impl! { A, B, C } +async_fn_impl! { A, B, C, D } +async_fn_impl! { A, B, C, D, E } +async_fn_impl! { A, B, C, D, E, F } +async_fn_impl! { A, B, C, D, E, F, G } +async_fn_impl! { A, B, C, D, E, F, G, H } +async_fn_impl! { A, B, C, D, E, F, G, H, I } + #[cfg(test)] mod test { use xitca_service::ServiceExt; @@ -360,7 +402,7 @@ mod test { #[cfg(feature = "router")] #[test] fn handler_in_router() { - use crate::util::service::{route::get, Router}; + use crate::util::service::{Router, route::get}; let res = Router::new() .insert("/", get(handler_service(handler))) diff --git a/http/src/util/service/route.rs b/http/src/util/service/route.rs index b22df89ea..13871b82d 100644 --- a/http/src/util/service/route.rs +++ b/http/src/util/service/route.rs @@ -4,7 +4,7 @@ use core::{fmt, marker::PhantomData}; use std::error; -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; use crate::http::{BorrowReq, Method}; @@ -237,7 +237,7 @@ where mod test { use std::convert::Infallible; - use xitca_service::{fn_service, ServiceExt}; + use xitca_service::{ServiceExt, fn_service}; use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ diff --git a/http/src/util/service/router.rs b/http/src/util/service/router.rs index f3c8b48c6..394154d90 100644 --- a/http/src/util/service/router.rs +++ b/http/src/util/service/router.rs @@ -1,10 +1,10 @@ -pub use xitca_router::{params::Params, MatchError}; +pub use xitca_router::{MatchError, params::Params}; use core::{fmt, marker::PhantomData}; use std::{collections::HashMap, error}; -use xitca_service::{object::BoxedServiceObject, pipeline::PipelineT, BoxFuture, FnService, Service}; +use xitca_service::{BoxFuture, FnService, Service, object::BoxedServiceObject, pipeline::PipelineT}; use crate::http::Request; @@ -55,10 +55,11 @@ impl Router { Req: IntoObject, Arg, Object = Obj>, { let path = builder.path_gen(path); - assert!(self - .routes - .insert(path, Req::into_object(F::route_gen(builder))) - .is_none()); + assert!( + self.routes + .insert(path, Req::into_object(F::route_gen(builder))) + .is_none() + ); self } @@ -493,7 +494,7 @@ mod service { mod test { use core::convert::Infallible; - use xitca_service::{fn_service, ready::ReadyService, ServiceExt}; + use xitca_service::{ServiceExt, fn_service, ready::ReadyService}; use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ diff --git a/http/src/util/timer.rs b/http/src/util/timer.rs index f06bccac8..b9af89afe 100644 --- a/http/src/util/timer.rs +++ b/http/src/util/timer.rs @@ -1,11 +1,11 @@ use std::{ future::Future, pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use pin_project_lite::pin_project; -use tokio::time::{sleep_until, Instant, Sleep}; +use tokio::time::{Instant, Sleep, sleep_until}; pub(crate) trait Timeout: Sized { fn timeout(self, timer: Pin<&mut KeepAlive>) -> TimeoutFuture<'_, Self>; diff --git a/server/CHANGES.md b/server/CHANGES.md index daf35a208..9db194bb7 100644 --- a/server/CHANGES.md +++ b/server/CHANGES.md @@ -1,5 +1,6 @@ # unreleased 0.5.0 ## Change +- bump MSRV to `1.85` and Rust edition 2024 - rename `net::AsListener` trait to `IntoListener`. improve it's interface and reduce possibility of panicing - update `xitca-service` to `0.3.0` @@ -22,4 +23,4 @@ # 0.2.0 ## Change -- update `xitca-io` to `0.2.0` \ No newline at end of file +- update `xitca-io` to `0.2.0` diff --git a/server/Cargo.toml b/server/Cargo.toml index 6fb0082ce..dcd468fa0 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xitca-server" version = "0.5.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" description = "http server for xitca" repository = "https://github.com/HFQR/xitca-web" diff --git a/server/src/server/future.rs b/server/src/server/future.rs index c3769c1f5..bc9005bd9 100644 --- a/server/src/server/future.rs +++ b/server/src/server/future.rs @@ -2,12 +2,12 @@ use std::{ future::Future, io, mem, pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use crate::signals::{self, Signal, SignalFuture}; -use super::{handle::ServerHandle, Command, Server}; +use super::{Command, Server, handle::ServerHandle}; #[must_use = "ServerFuture must be .await/ spawn as task / consumed with ServerFuture::wait."] pub enum ServerFuture { @@ -83,7 +83,9 @@ impl ServerFuture { let (mut server_fut, cmd) = match tokio::runtime::Handle::try_current() { Ok(_) => { - tracing::warn!("ServerFuture::wait is called from within tokio context. It would block current thread from handling async tasks."); + tracing::warn!( + "ServerFuture::wait is called from within tokio context. It would block current thread from handling async tasks." + ); std::thread::Builder::new() .name(String::from("xitca-server-wait-scoped")) .spawn(func)? diff --git a/server/src/server/mod.rs b/server/src/server/mod.rs index 869fc76ed..1dbff3ab8 100644 --- a/server/src/server/mod.rs +++ b/server/src/server/mod.rs @@ -9,8 +9,8 @@ pub(crate) use self::service::{IntoServiceObj, ServiceObj}; use std::{ io, mem, sync::{ - atomic::{AtomicBool, Ordering}, Arc, + atomic::{AtomicBool, Ordering}, }, thread, }; diff --git a/server/src/server/service.rs b/server/src/server/service.rs index c3c664d01..18dcee981 100644 --- a/server/src/server/service.rs +++ b/server/src/server/service.rs @@ -2,7 +2,7 @@ use std::{marker::PhantomData, rc::Rc, sync::Arc}; use tokio::task::JoinHandle; use xitca_io::net::{Listener, Stream}; -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; use crate::worker::{self, ServiceAny}; diff --git a/server/src/worker/mod.rs b/server/src/worker/mod.rs index 3e78c3662..e3b501fd5 100644 --- a/server/src/worker/mod.rs +++ b/server/src/worker/mod.rs @@ -7,7 +7,7 @@ use std::{io, rc::Rc, sync::Arc, thread}; use tokio::{task::JoinHandle, time::sleep}; use tracing::{error, info}; use xitca_io::net::{Listener, Stream}; -use xitca_service::{ready::ReadyService, Service}; +use xitca_service::{Service, ready::ReadyService}; use self::shutdown::ShutdownHandle; diff --git a/server/src/worker/shutdown.rs b/server/src/worker/shutdown.rs index 493286aee..c9fdb8b37 100644 --- a/server/src/worker/shutdown.rs +++ b/server/src/worker/shutdown.rs @@ -6,7 +6,7 @@ use std::{ use tracing::info; -use super::{with_worker_name_str, ServiceAny}; +use super::{ServiceAny, with_worker_name_str}; pub(super) struct ShutdownHandle<'a> { shutdown_timeout: Duration, diff --git a/service/CHANGES.md b/service/CHANGES.md index 3bdcc2d9d..9c7e440bb 100644 --- a/service/CHANGES.md +++ b/service/CHANGES.md @@ -1,9 +1,13 @@ # unreleased 0.3.0 +## Change +- bump MSRV to 1.85 and Rust edition 2024 +- remove `AsyncClosure` trait. use `std::ops::AsyncFn` trait for functional middleware + ## Add - add `middleware::AsyncFn` middleware. `ServiceExt::enclosed_fn()` is equivalent to `ServiceExt::enclosed(middleware::AsyncFn())` -## Change -- rename `AsyncClosure` trait to `AsyncFn` +## Remove +- remove `std` feature. crate becomes fully no_std # 0.2.0 ## Change diff --git a/service/Cargo.toml b/service/Cargo.toml index 5a54eead6..38a9f0c11 100644 --- a/service/Cargo.toml +++ b/service/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xitca-service" version = "0.3.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" description = "async traits for xitca" repository = "https://github.com/HFQR/xitca-web" @@ -14,7 +14,6 @@ workspace = true [features] alloc = [] -std = [] [dev-dependencies] xitca-unsafe-collection = "0.2.0" diff --git a/service/src/async_fn.rs b/service/src/async_fn.rs deleted file mode 100644 index 8f551976c..000000000 --- a/service/src/async_fn.rs +++ /dev/null @@ -1,44 +0,0 @@ -#![allow(non_snake_case)] - -use core::future::Future; - -/// Same as `std::ops::Fn` trait but for async output. -/// -/// It is necessary in the the HRTB bounds for async fn's with reference parameters because it -/// allows the output future to be bound to the parameter lifetime. -/// `F: for<'a> AsyncFn<(&'a u8,) Output=u8>` -pub trait AsyncFn { - type Output; - type Future: Future; - - fn call(&self, arg: Arg) -> Self::Future; -} - -macro_rules! async_closure_impl { - ($($arg: ident),*) => { - impl AsyncFn<($($arg,)*)> for Func - where - Func: Fn($($arg),*) -> Fut, - Fut: Future, - { - type Output = Fut::Output; - type Future = Fut; - - #[inline] - fn call(&self, ($($arg,)*): ($($arg,)*)) -> Self::Future { - self($($arg,)*) - } - } - } -} - -async_closure_impl! {} -async_closure_impl! { A } -async_closure_impl! { A, B } -async_closure_impl! { A, B, C } -async_closure_impl! { A, B, C, D } -async_closure_impl! { A, B, C, D, E } -async_closure_impl! { A, B, C, D, E, F } -async_closure_impl! { A, B, C, D, E, F, G } -async_closure_impl! { A, B, C, D, E, F, G, H } -async_closure_impl! { A, B, C, D, E, F, G, H, I } diff --git a/service/src/lib.rs b/service/src/lib.rs index 4659da909..4957dc87c 100644 --- a/service/src/lib.rs +++ b/service/src/lib.rs @@ -37,7 +37,6 @@ #![no_std] #![forbid(unsafe_code)] -mod async_fn; mod service; pub mod middleware; @@ -45,9 +44,8 @@ pub mod pipeline; pub mod ready; pub use self::{ - async_fn::AsyncFn, pipeline::{EnclosedBuilder, EnclosedFnBuilder, MapBuilder, MapErrorBuilder}, - service::{fn_build, fn_service, FnService, Service, ServiceExt}, + service::{FnService, Service, ServiceExt, fn_build, fn_service}, }; #[cfg(feature = "alloc")] @@ -60,6 +58,3 @@ pub mod object; /// boxed [core::future::Future] trait object with no extra auto trait bound(`!Send` and `!Sync`). pub type BoxFuture<'a, Res, Err> = core::pin::Pin> + 'a>>; - -#[cfg(feature = "std")] -extern crate std; diff --git a/service/src/middleware/async_fn.rs b/service/src/middleware/async_fn.rs index 56bc81f7b..bb99b05e4 100644 --- a/service/src/middleware/async_fn.rs +++ b/service/src/middleware/async_fn.rs @@ -1,6 +1,5 @@ use crate::{ - async_fn, - pipeline::{marker, PipelineT}, + pipeline::{PipelineT, marker}, service::Service, }; @@ -24,13 +23,13 @@ where impl Service for PipelineT where - F: for<'s> async_fn::AsyncFn<(&'s S, Req), Output = Result>, + F: for<'s> core::ops::AsyncFn(&'s S, Req) -> Result, { type Response = Res; type Error = Err; #[inline] async fn call(&self, req: Req) -> Result { - self.second.call((&self.first, req)).await + (self.second)(&self.first, req).await } } diff --git a/service/src/object.rs b/service/src/object.rs index 7c4a01b85..deac58a8e 100644 --- a/service/src/object.rs +++ b/service/src/object.rs @@ -2,7 +2,7 @@ use alloc::boxed::Box; -use super::{service::Service, BoxFuture}; +use super::{BoxFuture, service::Service}; /// Object-safe counterpart of [Service]. pub trait ServiceObject { diff --git a/service/src/pipeline/enum.rs b/service/src/pipeline/enum.rs index cf8b671ac..e2b440caa 100644 --- a/service/src/pipeline/enum.rs +++ b/service/src/pipeline/enum.rs @@ -1,5 +1,6 @@ use core::{ convert::Infallible, + error::Error, fmt::{self, Debug, Display, Formatter}, }; @@ -90,7 +91,7 @@ where type Error = F::Error; async fn call(&self, req: Req) -> Result { - match self { + match *self { Self::First(ref f) => f.call(req).await, Self::Second(ref s) => s.call(req).await, } @@ -106,23 +107,22 @@ where #[inline] async fn ready(&self) -> Self::Ready { - match self { + match *self { Self::First(ref f) => Pipeline::First(f.ready().await), Self::Second(ref s) => Pipeline::Second(s.ready().await), } } } -#[cfg(feature = "std")] -impl std::error::Error for Pipeline +impl Error for Pipeline where - F: std::error::Error, - S: std::error::Error, + F: Error, + S: Error, { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { + fn source(&self) -> Option<&(dyn Error + 'static)> { match *self { - Self::First(ref f) => std::error::Error::source(f), - Self::Second(ref f) => std::error::Error::source(f), + Self::First(ref f) => Error::source(f), + Self::Second(ref f) => Error::source(f), } } } diff --git a/service/src/ready/and_then.rs b/service/src/ready/and_then.rs index dc1c550b0..04a9f5424 100644 --- a/service/src/ready/and_then.rs +++ b/service/src/ready/and_then.rs @@ -1,4 +1,4 @@ -use crate::pipeline::{marker::AndThen, PipelineT}; +use crate::pipeline::{PipelineT, marker::AndThen}; use super::ReadyService; diff --git a/service/src/ready/enclosed_fn.rs b/service/src/ready/enclosed_fn.rs index 2727d216a..d2a05e772 100644 --- a/service/src/ready/enclosed_fn.rs +++ b/service/src/ready/enclosed_fn.rs @@ -1,4 +1,4 @@ -use crate::pipeline::{marker::AsyncFn, PipelineT}; +use crate::pipeline::{PipelineT, marker::AsyncFn}; use super::ReadyService; diff --git a/service/src/ready/map.rs b/service/src/ready/map.rs index 5884b2ab0..5de9efe65 100644 --- a/service/src/ready/map.rs +++ b/service/src/ready/map.rs @@ -1,4 +1,4 @@ -use crate::pipeline::{marker::Map, PipelineT}; +use crate::pipeline::{PipelineT, marker::Map}; use super::ReadyService; diff --git a/service/src/ready/map_err.rs b/service/src/ready/map_err.rs index b0a852565..6738469b9 100644 --- a/service/src/ready/map_err.rs +++ b/service/src/ready/map_err.rs @@ -1,4 +1,4 @@ -use crate::pipeline::{marker::MapErr, PipelineT}; +use crate::pipeline::{PipelineT, marker::MapErr}; use super::ReadyService; diff --git a/service/src/service/and_then.rs b/service/src/service/and_then.rs index e10224749..71e5ca820 100644 --- a/service/src/service/and_then.rs +++ b/service/src/service/and_then.rs @@ -1,6 +1,6 @@ use crate::pipeline::{ - marker::{AndThen, BuildAndThen}, PipelineT, + marker::{AndThen, BuildAndThen}, }; use super::Service; diff --git a/service/src/service/enclosed.rs b/service/src/service/enclosed.rs index fec62a191..663666e8d 100644 --- a/service/src/service/enclosed.rs +++ b/service/src/service/enclosed.rs @@ -1,4 +1,4 @@ -use crate::pipeline::{marker::BuildEnclosed, PipelineT}; +use crate::pipeline::{PipelineT, marker::BuildEnclosed}; use super::Service; diff --git a/service/src/service/ext.rs b/service/src/service/ext.rs index eb313d781..db0974e51 100644 --- a/service/src/service/ext.rs +++ b/service/src/service/ext.rs @@ -1,6 +1,6 @@ use crate::{ - async_fn, middleware, - pipeline::{marker, PipelineT}, + middleware, + pipeline::{PipelineT, marker}, }; use super::Service; @@ -18,9 +18,9 @@ pub trait ServiceExt: Service { } /// Function version of [Self::enclosed] method. - fn enclosed_fn(self, func: T) -> PipelineT, marker::BuildEnclosed> + fn enclosed_fn(self, func: T) -> PipelineT, marker::BuildEnclosed> where - T: for<'s> async_fn::AsyncFn<(&'s Self::Response, Req)> + Clone, + T: for<'s> AsyncFn(&'s Self::Response, Req) -> O + Clone, Self: Sized, { self.enclosed(middleware::AsyncFn(func)) @@ -135,13 +135,14 @@ mod test { where S: Service<&'static str, Response = &'static str, Error = ()>, { - let res = service.call(req).now_or_panic()?; + let res = service.call(req).await?; assert_eq!(res, "996"); Ok("251") } let res = fn_service(index) .enclosed_fn(enclosed) + .enclosed_fn(async |service, req| service.call(req).await) .call(()) .now_or_panic() .unwrap() diff --git a/service/src/service/function.rs b/service/src/service/function.rs index fa5e764fa..28c029530 100644 --- a/service/src/service/function.rs +++ b/service/src/service/function.rs @@ -1,6 +1,6 @@ use core::{ convert::Infallible, - future::{ready, Future, Ready}, + future::{Future, Ready, ready}, }; use super::Service; diff --git a/service/src/service/map.rs b/service/src/service/map.rs index 2e772fc06..3391a342c 100644 --- a/service/src/service/map.rs +++ b/service/src/service/map.rs @@ -1,6 +1,6 @@ use crate::pipeline::{ - marker::{BuildMap, Map}, PipelineT, + marker::{BuildMap, Map}, }; use super::Service; diff --git a/service/src/service/map_err.rs b/service/src/service/map_err.rs index 53f6b00f3..3996c36ce 100644 --- a/service/src/service/map_err.rs +++ b/service/src/service/map_err.rs @@ -1,6 +1,6 @@ use crate::pipeline::{ - marker::{BuildMapErr, MapErr}, PipelineT, + marker::{BuildMapErr, MapErr}, }; use super::Service; diff --git a/service/src/service/mod.rs b/service/src/service/mod.rs index 51e35b7d3..2579242be 100644 --- a/service/src/service/mod.rs +++ b/service/src/service/mod.rs @@ -8,7 +8,7 @@ mod opt; pub use self::{ ext::ServiceExt, - function::{fn_build, fn_service, FnService}, + function::{FnService, fn_build, fn_service}, }; use core::{future::Future, ops::Deref, pin::Pin}; diff --git a/service/src/service/opt.rs b/service/src/service/opt.rs index 581554ccd..1e95ad661 100644 --- a/service/src/service/opt.rs +++ b/service/src/service/opt.rs @@ -12,7 +12,7 @@ where type Error = T::Error; async fn call(&self, res: Result) -> Result { - match self { + match *self { None => res.map(PipelineE::First), Some(ref t) => t.call(res).await.map(PipelineE::Second), } diff --git a/web/CHANGES.md b/web/CHANGES.md index 92c3fbaee..73bc78ff8 100644 --- a/web/CHANGES.md +++ b/web/CHANGES.md @@ -8,6 +8,7 @@ - add `Pin<&mut RequestStream>` argument to `handler::websocket::Websocket::on_close` method ## Change +- bump MSRV to `1.85` and Rust edition 2024 - change `error::Error` type by removing it's generic type param. Everywhere it had to be written as `Error` can now be written as plain `Error`. Side effect of this change is how error interact with application state(typed data passed into `App::with_state` API). For most cases error type don't interact with app state at all and their impl don't need any change. But in rare case where it's needed it has to be changed in the following pattern: ```rust struct CustomError; diff --git a/web/Cargo.toml b/web/Cargo.toml index 0e07e6c38..46a56f146 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "xitca-web" version = "0.7.0" -edition = "2021" +edition = "2024" license = "Apache-2.0" description = "an async web framework" repository = "https://github.com/HFQR/xitca-web" @@ -84,7 +84,7 @@ __server = ["xitca-http/runtime", "xitca-server"] [dependencies] xitca-http = { version = "0.7.0", features = ["router"], default-features = false } -xitca-service = { version = "0.3.0", features = ["alloc", "std"] } +xitca-service = { version = "0.3.0", features = ["alloc"] } xitca-unsafe-collection = "0.2.0" futures-core = "0.3" diff --git a/web/src/app/mod.rs b/web/src/app/mod.rs index cf5b096b7..ea9c7c136 100644 --- a/web/src/app/mod.rs +++ b/web/src/app/mod.rs @@ -4,7 +4,7 @@ mod router; use core::{ convert::Infallible, fmt, - future::{ready, Future}, + future::{Future, ready}, pin::Pin, }; @@ -23,7 +23,7 @@ use crate::{ error::{Error, RouterError}, http::{WebRequest, WebResponse}, middleware::eraser::TypeEraser, - service::{ready::ReadyService, AsyncFn, EnclosedBuilder, EnclosedFnBuilder, MapBuilder, Service, ServiceExt}, + service::{EnclosedBuilder, EnclosedFnBuilder, MapBuilder, Service, ServiceExt, ready::ReadyService}, }; use self::{object::WebObject, router::AppRouter}; @@ -414,9 +414,9 @@ where /// Enclose App with function as middleware type. /// See [middleware](crate::middleware) for more. - pub fn enclosed_fn(self, transform: T) -> App, CF> + pub fn enclosed_fn(self, transform: T) -> App, CF> where - T: for<'s> AsyncFn<(&'s R::Response, Req)> + Clone, + T: for<'s> AsyncFn(&'s R::Response, Req) -> O + Clone, { App { router: self.router.enclosed_fn(transform), @@ -503,7 +503,7 @@ where ) -> crate::server::HttpServer< impl Service< Response = impl ReadyService - + Service>, Error = Infallible>, + + Service>, Error = Infallible>, Error = impl fmt::Debug, >, > @@ -610,7 +610,7 @@ mod test { extension::ExtensionRef, extension::ExtensionsRef, handler_service, path::PathRef, state::StateRef, uri::UriRef, }, - http::{const_header_value::TEXT_UTF8, header::CONTENT_TYPE, request, Method}, + http::{Method, const_header_value::TEXT_UTF8, header::CONTENT_TYPE, request}, middleware::UncheckedReady, route::get, }; diff --git a/web/src/app/object.rs b/web/src/app/object.rs index f473efa9c..5ae5a53ca 100644 --- a/web/src/app/object.rs +++ b/web/src/app/object.rs @@ -1,7 +1,7 @@ use core::marker::PhantomData; use xitca_http::util::service::router::{IntoObject, PathGen, RouteGen, RouteObject}; -use xitca_service::{object::ServiceObject, Service}; +use xitca_service::{Service, object::ServiceObject}; use crate::context::WebContext; diff --git a/web/src/app/router.rs b/web/src/app/router.rs index 422a3d864..d53da4612 100644 --- a/web/src/app/router.rs +++ b/web/src/app/router.rs @@ -1,9 +1,9 @@ use xitca_http::util::service::router::{IntoObject, PathGen, RouteGen, Router, RouterError, RouterMapErr, TypedRoute}; use crate::{ - error::Error, - service::{ready::ReadyService, Service}, WebContext, + error::Error, + service::{Service, ready::ReadyService}, }; /// application wrap around [Router] and transform it's error type into [Error] diff --git a/web/src/body.rs b/web/src/body.rs index e3a01087c..ae0ed8452 100644 --- a/web/src/body.rs +++ b/web/src/body.rs @@ -2,7 +2,7 @@ use futures_core::stream::Stream; -pub use xitca_http::body::{none_body_hint, BoxBody, RequestBody, ResponseBody, NONE_BODY_HINT}; +pub use xitca_http::body::{BoxBody, NONE_BODY_HINT, RequestBody, ResponseBody, none_body_hint}; pub(crate) use xitca_http::body::Either; diff --git a/web/src/error/mod.rs b/web/src/error/mod.rs index eb062c228..d44658498 100644 --- a/web/src/error/mod.rs +++ b/web/src/error/mod.rs @@ -89,7 +89,7 @@ use std::{error, io, sync::Mutex}; use crate::{ context::WebContext, http::WebResponse, - service::{pipeline::PipelineE, Service}, + service::{Service, pipeline::PipelineE}, }; use self::service_impl::ErrorService; diff --git a/web/src/error/router.rs b/web/src/error/router.rs index f7948d572..1c86b57f7 100644 --- a/web/src/error/router.rs +++ b/web/src/error/router.rs @@ -6,13 +6,13 @@ pub use xitca_http::util::service::{ use core::convert::Infallible; use crate::{ + WebContext, body::ResponseBody, - http::{header::ALLOW, StatusCode, WebResponse}, + http::{StatusCode, WebResponse, header::ALLOW}, service::Service, - WebContext, }; -use super::{blank_error_service, error_from_service, Error}; +use super::{Error, blank_error_service, error_from_service}; error_from_service!(MatchError); blank_error_service!(MatchError, StatusCode::NOT_FOUND); diff --git a/web/src/error/status.rs b/web/src/error/status.rs index 89283fdcd..148677b55 100644 --- a/web/src/error/status.rs +++ b/web/src/error/status.rs @@ -5,10 +5,10 @@ use std::error; use std::backtrace::Backtrace; use crate::{ + WebContext, body::ResponseBody, http::{StatusCode, WebResponse}, service::Service, - WebContext, }; use super::Error; diff --git a/web/src/handler/impls.rs b/web/src/handler/impls.rs index d5d71e8b9..0e5b27bef 100644 --- a/web/src/handler/impls.rs +++ b/web/src/handler/impls.rs @@ -209,7 +209,7 @@ const _: () = { mod test { use xitca_unsafe_collection::futures::NowOrPanic; - use crate::http::header::{HeaderMap, HeaderValue, CONTENT_TYPE, COOKIE}; + use crate::http::header::{CONTENT_TYPE, COOKIE, HeaderMap, HeaderValue}; use super::*; diff --git a/web/src/handler/mod.rs b/web/src/handler/mod.rs index 18d21b6c7..57384f304 100644 --- a/web/src/handler/mod.rs +++ b/web/src/handler/mod.rs @@ -12,4 +12,4 @@ pub use types::*; #[cfg(not(target_family = "wasm"))] pub use sync::handler_sync_service; -pub use xitca_http::util::service::handler::{handler_service, FromRequest, Responder}; +pub use xitca_http::util::service::handler::{FromRequest, Responder, handler_service}; diff --git a/web/src/handler/sync.rs b/web/src/handler/sync.rs index 56c85576a..402a8f294 100644 --- a/web/src/handler/sync.rs +++ b/web/src/handler/sync.rs @@ -2,13 +2,13 @@ use core::{ convert::Infallible, - future::{ready, Ready}, + future::{Ready, ready}, marker::PhantomData, }; use super::{FromRequest, Responder}; -use xitca_service::{fn_build, FnService, Service}; +use xitca_service::{FnService, Service, fn_build}; /// synchronous version of [handler_service] /// diff --git a/web/src/handler/types/cookie.rs b/web/src/handler/types/cookie.rs index c60cb3dfd..fde9a7416 100644 --- a/web/src/handler/types/cookie.rs +++ b/web/src/handler/types/cookie.rs @@ -7,15 +7,15 @@ pub use cookie::{Cookie, Key, ParseError}; use cookie::CookieJar as _CookieJar; use crate::{ + WebContext, body::ResponseBody, - error::{error_from_service, forward_blank_bad_request, Error, ErrorStatus, ExtensionNotFound, HeaderNotFound}, + error::{Error, ErrorStatus, ExtensionNotFound, HeaderNotFound, error_from_service, forward_blank_bad_request}, handler::{FromRequest, Responder}, http::{ - header::ToStrError, - header::{HeaderValue, COOKIE, SET_COOKIE}, WebResponse, + header::ToStrError, + header::{COOKIE, HeaderValue, SET_COOKIE}, }, - WebContext, }; macro_rules! key_impl { diff --git a/web/src/handler/types/form.rs b/web/src/handler/types/form.rs index 3875c79c9..d6efbdc02 100644 --- a/web/src/handler/types/form.rs +++ b/web/src/handler/types/form.rs @@ -4,18 +4,18 @@ use core::{ ops::{Deref, DerefMut}, }; -use serde::{de::Deserialize, Serialize}; +use serde::{Serialize, de::Deserialize}; use crate::{ body::BodyStream, bytes::{Bytes, BytesMut}, context::WebContext, - error::{error_from_service, forward_blank_bad_request, Error}, + error::{Error, error_from_service, forward_blank_bad_request}, handler::{ - header::{self, HeaderRef}, FromRequest, Responder, + header::{self, HeaderRef}, }, - http::{const_header_value::APPLICATION_WWW_FORM_URLENCODED, header::CONTENT_TYPE, WebResponse}, + http::{WebResponse, const_header_value::APPLICATION_WWW_FORM_URLENCODED, header::CONTENT_TYPE}, }; use super::body::Limit; diff --git a/web/src/handler/types/header.rs b/web/src/handler/types/header.rs index 1d96ed19c..15ffebcc7 100644 --- a/web/src/handler/types/header.rs +++ b/web/src/handler/types/header.rs @@ -8,8 +8,8 @@ use crate::{ error::{Error, HeaderNotFound}, handler::{FromRequest, Responder}, http::{ - header::{self, HeaderMap, HeaderName, HeaderValue}, WebResponse, + header::{self, HeaderMap, HeaderName, HeaderValue}, }, }; diff --git a/web/src/handler/types/html.rs b/web/src/handler/types/html.rs index 7070e7f40..be7eb92f0 100644 --- a/web/src/handler/types/html.rs +++ b/web/src/handler/types/html.rs @@ -9,7 +9,7 @@ use crate::{ context::WebContext, error::Error, handler::Responder, - http::{const_header_value::TEXT_HTML_UTF8, header::CONTENT_TYPE, WebResponse}, + http::{WebResponse, const_header_value::TEXT_HTML_UTF8, header::CONTENT_TYPE}, service::Service, }; @@ -84,7 +84,7 @@ where mod test { use xitca_unsafe_collection::futures::NowOrPanic; - use crate::{http::WebRequest, App}; + use crate::{App, http::WebRequest}; use super::*; diff --git a/web/src/handler/types/json.rs b/web/src/handler/types/json.rs index 3dbb82c8f..8bdede83b 100644 --- a/web/src/handler/types/json.rs +++ b/web/src/handler/types/json.rs @@ -14,9 +14,9 @@ use crate::{ body::BodyStream, bytes::{BufMutWriter, Bytes, BytesMut}, context::WebContext, - error::{error_from_service, forward_blank_bad_request, Error}, + error::{Error, error_from_service, forward_blank_bad_request}, handler::{FromRequest, Responder}, - http::{const_header_value::JSON, header::CONTENT_TYPE, WebResponse}, + http::{WebResponse, const_header_value::JSON, header::CONTENT_TYPE}, service::Service, }; @@ -229,10 +229,10 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, handler::handler_service, - http::{header::CONTENT_LENGTH, WebRequest}, + http::{WebRequest, header::CONTENT_LENGTH}, test::collect_string_body, - App, }; use super::*; diff --git a/web/src/handler/types/multipart.rs b/web/src/handler/types/multipart.rs index a38d35c78..877171f6d 100644 --- a/web/src/handler/types/multipart.rs +++ b/web/src/handler/types/multipart.rs @@ -1,7 +1,7 @@ use crate::{ body::{BodyStream, RequestBody}, context::WebContext, - error::{forward_blank_bad_request, Error}, + error::{Error, forward_blank_bad_request}, handler::FromRequest, }; @@ -29,15 +29,16 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, handler::handler_service, http::{ - header::{HeaderValue, CONTENT_TYPE, TRANSFER_ENCODING}, - request, Method, RequestExt, + Method, RequestExt, + header::{CONTENT_TYPE, HeaderValue, TRANSFER_ENCODING}, + request, }, route::post, service::Service, test::collect_body, - App, }; use super::*; diff --git a/web/src/handler/types/params.rs b/web/src/handler/types/params.rs index c570c65f1..74c95ea99 100644 --- a/web/src/handler/types/params.rs +++ b/web/src/handler/types/params.rs @@ -3,8 +3,9 @@ use core::{marker::PhantomData, ops::Deref}; use serde::{ + Deserialize, de::{self, Deserializer, Error as DeError, Visitor}, - forward_to_deserialize_any, Deserialize, + forward_to_deserialize_any, }; use xitca_http::util::service::router; @@ -519,10 +520,10 @@ mod tests { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, http::{Request, RequestExt, Uri}, - service::{fn_service, Service}, + service::{Service, fn_service}, test::collect_string_body, - App, }; use super::*; diff --git a/web/src/handler/types/redirect.rs b/web/src/handler/types/redirect.rs index ac4218d0a..0a0b884a1 100644 --- a/web/src/handler/types/redirect.rs +++ b/web/src/handler/types/redirect.rs @@ -10,8 +10,8 @@ use crate::{ error::Error, handler::Responder, http::{ - header::{HeaderValue, LOCATION}, StatusCode, WebResponse, + header::{HeaderValue, LOCATION}, }, service::Service, }; @@ -94,7 +94,7 @@ impl<'r, C, B> Service> for Redirect { mod test { use xitca_unsafe_collection::futures::NowOrPanic; - use crate::{http::WebRequest, App}; + use crate::{App, http::WebRequest}; use super::*; diff --git a/web/src/handler/types/state.rs b/web/src/handler/types/state.rs index 438a2a711..93dd3cb65 100644 --- a/web/src/handler/types/state.rs +++ b/web/src/handler/types/state.rs @@ -141,7 +141,7 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; - use crate::{handler::handler_service, http::WebRequest, route::get, service::Service, App}; + use crate::{App, handler::handler_service, http::WebRequest, route::get, service::Service}; use super::*; diff --git a/web/src/handler/types/text.rs b/web/src/handler/types/text.rs index a0f51965f..80124450c 100644 --- a/web/src/handler/types/text.rs +++ b/web/src/handler/types/text.rs @@ -5,9 +5,9 @@ use core::convert::Infallible; use crate::{ body::{BodyStream, ResponseBody}, context::WebContext, - error::{forward_blank_bad_request, Error}, + error::{Error, forward_blank_bad_request}, handler::{FromRequest, Responder}, - http::{const_header_value::TEXT_UTF8, header::CONTENT_TYPE, WebResponse}, + http::{WebResponse, const_header_value::TEXT_UTF8, header::CONTENT_TYPE}, service::Service, }; diff --git a/web/src/handler/types/websocket.rs b/web/src/handler/types/websocket.rs index 1f0a636ae..3a1f610ea 100644 --- a/web/src/handler/types/websocket.rs +++ b/web/src/handler/types/websocket.rs @@ -1,8 +1,8 @@ use core::{ cmp::Ordering, convert::Infallible, - future::{poll_fn, Future}, - pin::{pin, Pin}, + future::{Future, poll_fn}, + pin::{Pin, pin}, time::Duration, }; @@ -10,10 +10,10 @@ use std::io; use futures_core::stream::Stream; use http_ws::{ - stream::{RequestStream, WsError}, HandshakeError, Item, Message as WsMessage, ProtocolError, WsOutput, + stream::{RequestStream, WsError}, }; -use tokio::time::{sleep, Instant}; +use tokio::time::{Instant, sleep}; use xitca_unsafe_collection::{ bytes::BytesStr, futures::{Select, SelectOutput}, @@ -26,8 +26,8 @@ use crate::{ error::{Error, HeaderNotFound}, handler::{FromRequest, Responder}, http::{ - header::{CONNECTION, SEC_WEBSOCKET_VERSION, UPGRADE}, StatusCode, WebResponse, + header::{CONNECTION, SEC_WEBSOCKET_VERSION, UPGRADE}, }, service::Service, }; diff --git a/web/src/lib.rs b/web/src/lib.rs index 5762df692..5e67a1ed3 100644 --- a/web/src/lib.rs +++ b/web/src/lib.rs @@ -354,7 +354,7 @@ pub mod route { //! # Ok(()) //! # } //! ``` - pub use xitca_http::util::service::route::{connect, delete, get, head, options, patch, post, put, trace, Route}; + pub use xitca_http::util::service::route::{Route, connect, delete, get, head, options, patch, post, put, trace}; } pub use app::{App, AppObject, NestApp}; diff --git a/web/src/middleware/catch_unwind.rs b/web/src/middleware/catch_unwind.rs index 0033e672b..cf72a2c93 100644 --- a/web/src/middleware/catch_unwind.rs +++ b/web/src/middleware/catch_unwind.rs @@ -3,9 +3,9 @@ use xitca_http::util::middleware::catch_unwind::{self, CatchUnwindError}; use crate::{ - error::{Error, ThreadJoinError}, - service::{ready::ReadyService, Service}, WebContext, + error::{Error, ThreadJoinError}, + service::{Service, ready::ReadyService}, }; /// middleware for catching panic inside [`Service::call`] and return a 500 error response. @@ -91,9 +91,9 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, handler::handler_service, http::{Request, StatusCode}, - App, }; use super::*; diff --git a/web/src/middleware/compress.rs b/web/src/middleware/compress.rs index 9c3c022bf..db01b3556 100644 --- a/web/src/middleware/compress.rs +++ b/web/src/middleware/compress.rs @@ -28,12 +28,12 @@ impl Service> for Compress { } } mod service { - use http_encoding::{encoder, Coder, ContentEncoding}; + use http_encoding::{Coder, ContentEncoding, encoder}; use crate::{ body::{BodyStream, NONE_BODY_HINT}, - http::{header::HeaderMap, BorrowReq, WebResponse}, - service::{ready::ReadyService, Service}, + http::{BorrowReq, WebResponse, header::HeaderMap}, + service::{Service, ready::ReadyService}, }; pub struct CompressService(pub(super) S); @@ -80,7 +80,7 @@ mod service { mod test { use xitca_unsafe_collection::futures::NowOrPanic; - use crate::{handler::handler_service, http::WebRequest, App}; + use crate::{App, handler::handler_service, http::WebRequest}; use super::*; diff --git a/web/src/middleware/context.rs b/web/src/middleware/context.rs index 1265992d1..7de1e38b9 100644 --- a/web/src/middleware/context.rs +++ b/web/src/middleware/context.rs @@ -65,7 +65,7 @@ mod service { body::{Either, ResponseBody}, context::WebContext, http::{WebRequest, WebResponse}, - service::{ready::ReadyService, Service}, + service::{Service, ready::ReadyService}, }; pub struct WebContextService { diff --git a/web/src/middleware/decompress.rs b/web/src/middleware/decompress.rs index 9d65b95a2..d016ad27f 100644 --- a/web/src/middleware/decompress.rs +++ b/web/src/middleware/decompress.rs @@ -30,14 +30,14 @@ impl Service> for Decompress { mod service { use core::{cell::RefCell, convert::Infallible}; - use http_encoding::{error::EncodingError, Coder}; + use http_encoding::{Coder, error::EncodingError}; use crate::{ body::BodyStream, context::WebContext, - error::error_from_service, error::Error, - http::{const_header_value::TEXT_UTF8, header::CONTENT_TYPE, Request, StatusCode, WebResponse}, + error::error_from_service, + http::{Request, StatusCode, WebResponse, const_header_value::TEXT_UTF8, header::CONTENT_TYPE}, service::ready::ReadyService, }; @@ -105,16 +105,16 @@ mod service { #[cfg(test)] mod test { - use http_encoding::{encoder, ContentEncoding}; + use http_encoding::{ContentEncoding, encoder}; use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, body::ResponseBody, handler::handler_service, http::header::CONTENT_ENCODING, http::{WebRequest, WebResponse}, test::collect_body, - App, }; use super::*; diff --git a/web/src/middleware/eraser.rs b/web/src/middleware/eraser.rs index 652b8a4c6..73bd5d9c8 100644 --- a/web/src/middleware/eraser.rs +++ b/web/src/middleware/eraser.rs @@ -110,13 +110,13 @@ mod service { use core::cell::RefCell; use crate::{ + WebContext, body::{BodyStream, BoxBody}, body::{RequestBody, ResponseBody}, bytes::Bytes, error::Error, http::WebResponse, service::ready::ReadyService, - WebContext, }; use super::*; @@ -192,13 +192,13 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, WebContext, bytes::Bytes, error::Error, handler::handler_service, http::{Request, StatusCode, WebResponse}, middleware::Group, service::ServiceExt, - App, WebContext, }; use super::*; diff --git a/web/src/middleware/limit.rs b/web/src/middleware/limit.rs index cf202a0c5..de5234e0a 100644 --- a/web/src/middleware/limit.rs +++ b/web/src/middleware/limit.rs @@ -3,7 +3,7 @@ use std::{ cell::RefCell, pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use futures_core::stream::Stream; @@ -14,7 +14,7 @@ use crate::{ body::BodyStream, context::WebContext, error::{BodyError, BodyOverFlow}, - service::{ready::ReadyService, Service}, + service::{Service, ready::ReadyService}, }; /// General purposed limitation middleware. Limiting request/response body size etc. @@ -164,12 +164,12 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, body::BoxBody, bytes::Bytes, handler::{body::Body, handler_service}, http::{StatusCode, WebRequest}, test::collect_body, - App, }; use super::*; diff --git a/web/src/middleware/logger.rs b/web/src/middleware/logger.rs index d6accae59..ea15d720e 100644 --- a/web/src/middleware/logger.rs +++ b/web/src/middleware/logger.rs @@ -1,4 +1,4 @@ -use tracing::{warn, Level}; +use tracing::{Level, warn}; use xitca_http::util::middleware; use crate::service::Service; diff --git a/web/src/middleware/mod.rs b/web/src/middleware/mod.rs index 614fde16d..efacc7adb 100644 --- a/web/src/middleware/mod.rs +++ b/web/src/middleware/mod.rs @@ -326,11 +326,11 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, handler::{extension::ExtensionRef, handler_service}, http::{Request, RequestExt}, service::Service, test::collect_string_body, - App, }; use super::*; diff --git a/web/src/middleware/rate_limit.rs b/web/src/middleware/rate_limit.rs index a9d92df72..861ccb062 100644 --- a/web/src/middleware/rate_limit.rs +++ b/web/src/middleware/rate_limit.rs @@ -63,11 +63,11 @@ mod service { use core::convert::Infallible; use crate::{ + WebContext, body::ResponseBody, error::Error, http::WebResponse, - service::{ready::ReadyService, Service}, - WebContext, + service::{Service, ready::ReadyService}, }; pub struct RateLimitService { diff --git a/web/src/middleware/sync.rs b/web/src/middleware/sync.rs index 45f29794a..260138db3 100644 --- a/web/src/middleware/sync.rs +++ b/web/src/middleware/sync.rs @@ -149,10 +149,10 @@ mod test { use core::convert::Infallible; use crate::{ + App, body::ResponseBody, http::{StatusCode, WebResponse}, service::fn_service, - App, }; use super::*; diff --git a/web/src/middleware/tower_http_compat.rs b/web/src/middleware/tower_http_compat.rs index 71b82b60d..cfdde4f42 100644 --- a/web/src/middleware/tower_http_compat.rs +++ b/web/src/middleware/tower_http_compat.rs @@ -2,7 +2,7 @@ use tower_layer::Layer; -use crate::service::{tower_http_compat::TowerCompatService, Service}; +use crate::service::{Service, tower_http_compat::TowerCompatService}; /// A middleware type that bridge `xitca-service` and `tower-service`. /// Any `tower-http` type that impl [Layer] trait can be passed to it and used as xitca-web's middleware. @@ -70,9 +70,9 @@ mod compat_layer { use std::rc::Rc; use crate::{ + WebContext, http::{Request, RequestExt, Response, WebResponse}, service::tower_http_compat::{CompatReqBody, CompatResBody}, - WebContext, }; use super::*; @@ -125,11 +125,11 @@ mod test { use xitca_unsafe_collection::futures::NowOrPanic; use crate::{ + App, WebContext, body::ResponseBody, http::WebRequest, http::{StatusCode, WebResponse}, service::fn_service, - App, WebContext, }; use super::*; diff --git a/web/src/server.rs b/web/src/server.rs index 84506969a..6c718fb27 100644 --- a/web/src/server.rs +++ b/web/src/server.rs @@ -2,17 +2,17 @@ use std::{fmt, future::Future, sync::Arc, time::Duration}; use futures_core::stream::Stream; use xitca_http::{ - body::RequestBody, - config::{HttpServiceConfig, DEFAULT_HEADER_LIMIT, DEFAULT_READ_BUF_LIMIT, DEFAULT_WRITE_BUF_LIMIT}, HttpServiceBuilder, + body::RequestBody, + config::{DEFAULT_HEADER_LIMIT, DEFAULT_READ_BUF_LIMIT, DEFAULT_WRITE_BUF_LIMIT, HttpServiceConfig}, }; -use xitca_server::{net::IntoListener, Builder, ServerFuture}; +use xitca_server::{Builder, ServerFuture, net::IntoListener}; use xitca_service::ServiceExt; use crate::{ bytes::Bytes, http::{Request, RequestExt, Response}, - service::{ready::ReadyService, Service}, + service::{Service, ready::ReadyService}, }; /// multi protocol handling http server @@ -174,7 +174,6 @@ where S::Response: ReadyService + Service>, Response = Response> + 'static, S::Error: fmt::Debug, >>>::Error: fmt::Debug, - ResB: Stream> + 'static, BE: fmt::Debug + 'static, { @@ -190,7 +189,6 @@ where S::Response: ReadyService + Service>, Response = Response> + 'static, S::Error: fmt::Debug, >>>::Error: fmt::Debug, - ResB: Stream> + 'static, BE: fmt::Debug + 'static, L: IntoListener + 'static, @@ -212,7 +210,6 @@ where S::Response: ReadyService + Service>, Response = Response> + 'static, S::Error: fmt::Debug, >>>::Error: fmt::Debug, - ResB: Stream> + 'static, BE: fmt::Debug + 'static, { @@ -269,7 +266,6 @@ where S::Response: ReadyService + Service>, Response = Response> + 'static, S::Error: fmt::Debug, >>>::Error: fmt::Debug, - ResB: Stream> + 'static, BE: fmt::Debug + 'static, { @@ -300,7 +296,6 @@ where S::Response: ReadyService + Service>, Response = Response> + 'static, S::Error: fmt::Debug, >>>::Error: fmt::Debug, - ResB: Stream> + 'static, BE: fmt::Debug + 'static, { diff --git a/web/src/service/file.rs b/web/src/service/file.rs index 24d2be8dd..535c89836 100644 --- a/web/src/service/file.rs +++ b/web/src/service/file.rs @@ -4,7 +4,7 @@ use core::convert::Infallible; use std::path::PathBuf; -use http_file::{runtime::AsyncFs, ServeDir as _ServeDir}; +use http_file::{ServeDir as _ServeDir, runtime::AsyncFs}; use xitca_http::util::service::router::{PathGen, RouteGen}; use crate::service::Service; @@ -99,7 +99,7 @@ where } mod service { - use http_file::{runtime::AsyncFs, ServeDir, ServeError}; + use http_file::{ServeDir, ServeError, runtime::AsyncFs}; use crate::{ body::ResponseBody, diff --git a/web/src/service/tower_http_compat.rs b/web/src/service/tower_http_compat.rs index 094fb83c2..c7a1fdee7 100644 --- a/web/src/service/tower_http_compat.rs +++ b/web/src/service/tower_http_compat.rs @@ -2,7 +2,7 @@ use core::{ cell::RefCell, convert::Infallible, pin::Pin, - task::{ready, Context, Poll}, + task::{Context, Poll, ready}, }; use std::borrow::Cow; @@ -11,7 +11,7 @@ use futures_core::stream::Stream; use http_body::{Body, Frame, SizeHint}; use pin_project_lite::pin_project; use xitca_http::{ - body::{none_body_hint, BodySize}, + body::{BodySize, none_body_hint}, util::service::router::{PathGen, RouteGen, RouterMapErr}, }; use xitca_unsafe_collection::fake::{FakeSend, FakeSync}; @@ -21,7 +21,7 @@ use crate::{ bytes::{Buf, Bytes, BytesMut}, context::WebContext, http::{Request, RequestExt, Response, WebResponse}, - service::{ready::ReadyService, Service}, + service::{Service, ready::ReadyService}, }; /// A middleware type that bridge `xitca-service` and `tower-service`. @@ -237,7 +237,7 @@ fn size_hint(size: BodySize) -> SizeHint { #[cfg(test)] mod test { - use xitca_http::body::{exact_body_hint, Once}; + use xitca_http::body::{Once, exact_body_hint}; use super::*;