diff --git a/examples/error-handle/src/main.rs b/examples/error-handle/src/main.rs index beb11e9c..38793b71 100644 --- a/examples/error-handle/src/main.rs +++ b/examples/error-handle/src/main.rs @@ -1,3 +1,5 @@ +#![feature(trait_upcasting)] + //! example of error handling in xitca-web. //! code must be compiled with nightly Rust. diff --git a/http/src/h2/proto/headers.rs b/http/src/h2/proto/headers.rs index 257c96ae..e2b72a56 100644 --- a/http/src/h2/proto/headers.rs +++ b/http/src/h2/proto/headers.rs @@ -550,7 +550,7 @@ where } } } - header => self.pseudo.from_header( + header => self.pseudo.parse( header, max_header_list_size, &mut self.is_over_size, @@ -606,7 +606,7 @@ where pub trait _Pseudo { fn into_iter(self) -> impl Iterator>> + Send; - fn from_header( + fn parse( &mut self, header: super::hpack::Header, max_header_list_size: usize, @@ -660,7 +660,7 @@ impl _Pseudo for Pseudo { Iter(self) } - fn from_header( + fn parse( &mut self, header: super::hpack::Header, max_header_list_size: usize, @@ -728,7 +728,7 @@ impl _Pseudo for ResponsePseudo { core::iter::once_with(move || super::hpack::Header::Status(self.status)) } - fn from_header( + fn parse( &mut self, header: super::hpack::Header, max_header_list_size: usize, @@ -767,7 +767,7 @@ impl _Pseudo for () { core::iter::empty() } - fn from_header(&mut self, _: super::hpack::Header, _: usize, _: &mut bool, _: bool, _: &mut bool, _: &mut usize) {} + fn parse(&mut self, _: super::hpack::Header, _: usize, _: &mut bool, _: bool, _: &mut bool, _: &mut usize) {} fn as_header_size(&self) -> usize { 0 diff --git a/web/CHANGES.md b/web/CHANGES.md index 43fc37a9..e2dd29d3 100644 --- a/web/CHANGES.md +++ b/web/CHANGES.md @@ -1,4 +1,6 @@ # unreleased +## Add +- `StateRef` can used for extracting `?Sized` type from application state. # 0.2.1 ## Add diff --git a/web/Cargo.toml b/web/Cargo.toml index d17700d1..81050972 100644 --- a/web/Cargo.toml +++ b/web/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "xitca-web" -version = "0.2.1" +version = "0.2.2" edition = "2021" license = "Apache-2.0" description = "an async web framework" diff --git a/web/src/error.rs b/web/src/error.rs index 8324dd84..5ab08127 100644 --- a/web/src/error.rs +++ b/web/src/error.rs @@ -144,7 +144,9 @@ use self::service_impl::ErrorService; /// assert_eq!(res.status().as_u16(), 200); /// /// // upcast and downcast to concrete error type again. -/// // *. trait upcast is a feature stabled in Rust 1.76 +/// // *. trait upcast is a nightly feature. +/// // see https://github.com/rust-lang/rust/issues/65991 for detail +/// /// // let e = &*e as &dyn error::Error; /// // assert!(e.downcast_ref::().is_some()); /// } diff --git a/web/src/handler/types/state.rs b/web/src/handler/types/state.rs index 27da954f..c87f411a 100644 --- a/web/src/handler/types/state.rs +++ b/web/src/handler/types/state.rs @@ -6,7 +6,9 @@ use crate::{body::BodyStream, context::WebContext, error::Error, handler::FromRe /// App state extractor. /// S type must be the same with the type passed to App::with_xxx_state(S). -pub struct StateRef<'a, S>(pub &'a S); +pub struct StateRef<'a, S>(pub &'a S) +where + S: ?Sized; impl fmt::Debug for StateRef<'_, S> { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { @@ -32,7 +34,7 @@ impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for StateRef<'a, T> where C: Borrow, B: BodyStream, - T: 'static, + T: ?Sized + 'static, { type Type<'b> = StateRef<'b, T>; type Error = Error;