Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

prepare new release for codegen. #923

Merged
merged 1 commit into from
Feb 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion client/src/h1/proto/dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,10 @@ where
match BodySize::from_stream(req.body()) {
// remove expect header if there is no body.
BodySize::None | BodySize::Sized(0) => {
req.headers_mut().remove(EXPECT);
let crate::http::header::Entry::Occupied(entry) = req.headers_mut().entry(EXPECT) else {
unreachable!()
};
entry.remove_entry();
is_expect = false;
}
_ => {}
Expand Down
2 changes: 2 additions & 0 deletions codegen/CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# unreleased

# 0.1.1
## Fix
- route macro is able to handle multiple `StateRef` and `StateOwn` arguments.
2 changes: 1 addition & 1 deletion codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "xitca-codegen"
version = "0.1.0"
version = "0.1.1"
edition = "2021"
license = "Apache-2.0"
description = "proc macro for xitca"
Expand Down
18 changes: 15 additions & 3 deletions web/src/handler/types/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,31 +86,42 @@ where

#[cfg(test)]
mod test {
use super::*;
use std::sync::Arc;

use xitca_codegen::State;
use xitca_unsafe_collection::futures::NowOrPanic;

use crate::{handler::handler_service, http::WebRequest, route::get, service::Service, App};

#[derive(State, Clone, Debug, Eq, PartialEq)]
use super::*;

#[derive(State, Clone, Debug)]
struct State {
#[borrow]
field1: String,
#[borrow]
field2: u32,
field3: Arc<dyn std::any::Any + Send + Sync>,
}

impl Borrow<dyn std::any::Any + Send + Sync> for State {
fn borrow(&self) -> &(dyn std::any::Any + Send + Sync) {
&*self.field3
}
}

async fn handler(
StateRef(state): StateRef<'_, String>,
StateRef(state2): StateRef<'_, u32>,
StateRef(state3): StateRef<'_, State>,
StateRef(state4): StateRef<'_, dyn std::any::Any + Send + Sync>,
ctx: &WebContext<'_, State>,
) -> String {
assert_eq!("state", state);
assert_eq!(&996, state2);
assert_eq!(state, ctx.state().field1.as_str());
assert_eq!(state3, ctx.state());
assert_eq!(state3.field1, ctx.state().field1);
assert!(state4.downcast_ref::<String>().is_some());
state.to_string()
}

Expand All @@ -119,6 +130,7 @@ mod test {
let state = State {
field1: String::from("state"),
field2: 996,
field3: Arc::new(String::new()),
};

App::new()
Expand Down
Loading