Skip to content

Commit

Permalink
enable extract ?Sized state with StateRef.
Browse files Browse the repository at this point in the history
  • Loading branch information
fakeshadow committed Jan 24, 2024
1 parent f2d64c5 commit f352bcc
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions web/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# unreleased
## Add
- `StateRef` can used for extracting `?Sized` type from application state.

# 0.2.1
## Add
Expand Down
2 changes: 1 addition & 1 deletion web/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
6 changes: 4 additions & 2 deletions web/src/handler/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: fmt::Debug> fmt::Debug for StateRef<'_, S> {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand All @@ -32,7 +34,7 @@ impl<'a, 'r, C, B, T> FromRequest<'a, WebContext<'r, C, B>> for StateRef<'a, T>
where
C: Borrow<T>,
B: BodyStream,
T: 'static,
T: ?Sized + 'static,
{
type Type<'b> = StateRef<'b, T>;
type Error = Error<C>;
Expand Down

0 comments on commit f352bcc

Please sign in to comment.