mirror of
https://gitlab.com/msrd0/gotham-restful.git
synced 2025-02-22 20:52:27 +00:00
fix implicit &'static mut State
error
This commit is contained in:
parent
681ef5d894
commit
f2bcc8438f
4 changed files with 27 additions and 11 deletions
|
@ -45,6 +45,7 @@ diesel = { version = "1.4.4", features = ["postgres"] }
|
||||||
futures-executor = "0.3.5"
|
futures-executor = "0.3.5"
|
||||||
paste = "1.0"
|
paste = "1.0"
|
||||||
pretty_env_logger = "0.4"
|
pretty_env_logger = "0.4"
|
||||||
|
tokio = { version = "0.2", features = ["time"], default-features = false }
|
||||||
thiserror = "1.0.18"
|
thiserror = "1.0.18"
|
||||||
trybuild = "1.0.27"
|
trybuild = "1.0.27"
|
||||||
|
|
||||||
|
|
|
@ -554,12 +554,12 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
|
||||||
}
|
}
|
||||||
type Body = #body_ty;
|
type Body = #body_ty;
|
||||||
|
|
||||||
fn handle(
|
fn handle<'a>(
|
||||||
state: &mut ::gotham_restful::gotham::state::State,
|
state: &'a mut ::gotham_restful::gotham::state::State,
|
||||||
placeholders: Self::Placeholders,
|
placeholders: Self::Placeholders,
|
||||||
params: Self::Params,
|
params: Self::Params,
|
||||||
body: ::std::option::Option<Self::Body>
|
body: ::std::option::Option<Self::Body>
|
||||||
) -> ::gotham_restful::export::BoxFuture<'static, Self::Output> {
|
) -> ::gotham_restful::export::BoxFuture<'a, Self::Output> {
|
||||||
#handle_content
|
#handle_content
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,12 +56,12 @@ pub trait Endpoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// The handler for this endpoint.
|
/// The handler for this endpoint.
|
||||||
fn handle(
|
fn handle<'a>(
|
||||||
state: &mut State,
|
state: &'a mut State,
|
||||||
placeholders: Self::Placeholders,
|
placeholders: Self::Placeholders,
|
||||||
params: Self::Params,
|
params: Self::Params,
|
||||||
body: Option<Self::Body>
|
body: Option<Self::Body>
|
||||||
) -> BoxFuture<'static, Self::Output>;
|
) -> BoxFuture<'a, Self::Output>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "openapi")]
|
#[cfg(feature = "openapi")]
|
||||||
|
@ -94,12 +94,12 @@ impl<E: EndpointWithSchema> Endpoint for E {
|
||||||
E::wants_auth()
|
E::wants_auth()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn handle(
|
fn handle<'a>(
|
||||||
state: &mut State,
|
state: &'a mut State,
|
||||||
placeholders: Self::Placeholders,
|
placeholders: Self::Placeholders,
|
||||||
params: Self::Params,
|
params: Self::Params,
|
||||||
body: Option<Self::Body>
|
body: Option<Self::Body>
|
||||||
) -> BoxFuture<'static, Self::Output> {
|
) -> BoxFuture<'a, Self::Output> {
|
||||||
E::handle(state, placeholders, params, body)
|
E::handle(state, placeholders, params, body)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,15 @@
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate gotham_derive;
|
extern crate gotham_derive;
|
||||||
|
|
||||||
use gotham::{router::builder::*, test::TestServer};
|
use gotham::{
|
||||||
|
hyper::{HeaderMap, Method},
|
||||||
|
router::builder::*,
|
||||||
|
test::TestServer
|
||||||
|
};
|
||||||
use gotham_restful::*;
|
use gotham_restful::*;
|
||||||
use mime::{APPLICATION_JSON, TEXT_PLAIN};
|
use mime::{APPLICATION_JSON, TEXT_PLAIN};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
use tokio::time::{delay_for, Duration};
|
||||||
|
|
||||||
mod util {
|
mod util {
|
||||||
include!("util/mod.rs");
|
include!("util/mod.rs");
|
||||||
|
@ -12,7 +17,7 @@ mod util {
|
||||||
use util::{test_delete_response, test_get_response, test_post_response, test_put_response};
|
use util::{test_delete_response, test_get_response, test_post_response, test_put_response};
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
#[resource(read_all, read, search, create, change_all, change, remove_all, remove)]
|
#[resource(read_all, read, search, create, change_all, change, remove_all, remove, state_test)]
|
||||||
struct FooResource;
|
struct FooResource;
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
@ -77,6 +82,15 @@ async fn remove(_id: u64) -> Raw<&'static [u8]> {
|
||||||
Raw::new(REMOVE_RESPONSE, TEXT_PLAIN)
|
Raw::new(REMOVE_RESPONSE, TEXT_PLAIN)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const STATE_TEST_RESPONSE: &[u8] = b"xxJbxOuwioqR5DfzPuVqvaqRSfpdNQGluIvHU4n1LM";
|
||||||
|
#[endpoint(method = "Method::GET", uri = "state_test")]
|
||||||
|
async fn state_test(state: &mut State) -> Raw<&'static [u8]> {
|
||||||
|
delay_for(Duration::from_nanos(1)).await;
|
||||||
|
state.borrow::<HeaderMap>();
|
||||||
|
delay_for(Duration::from_nanos(1)).await;
|
||||||
|
Raw::new(STATE_TEST_RESPONSE, TEXT_PLAIN)
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn async_methods() {
|
fn async_methods() {
|
||||||
let _ = pretty_env_logger::try_init_timed();
|
let _ = pretty_env_logger::try_init_timed();
|
||||||
|
@ -112,4 +126,5 @@ fn async_methods() {
|
||||||
);
|
);
|
||||||
test_delete_response(&server, "http://localhost/foo", REMOVE_ALL_RESPONSE);
|
test_delete_response(&server, "http://localhost/foo", REMOVE_ALL_RESPONSE);
|
||||||
test_delete_response(&server, "http://localhost/foo/1", REMOVE_RESPONSE);
|
test_delete_response(&server, "http://localhost/foo/1", REMOVE_RESPONSE);
|
||||||
|
test_get_response(&server, "http://localhost/foo/state_test", STATE_TEST_RESPONSE);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue