1
0
Fork 0
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:
Dominic 2021-01-18 19:04:06 +01:00
parent 681ef5d894
commit f2bcc8438f
Signed by: msrd0
GPG key ID: DCC8C247452E98F9
4 changed files with 27 additions and 11 deletions

View file

@ -45,6 +45,7 @@ diesel = { version = "1.4.4", features = ["postgres"] }
futures-executor = "0.3.5"
paste = "1.0"
pretty_env_logger = "0.4"
tokio = { version = "0.2", features = ["time"], default-features = false }
thiserror = "1.0.18"
trybuild = "1.0.27"

View file

@ -554,12 +554,12 @@ fn expand_endpoint_type(mut ty: EndpointType, attrs: AttributeArgs, fun: &ItemFn
}
type Body = #body_ty;
fn handle(
state: &mut ::gotham_restful::gotham::state::State,
fn handle<'a>(
state: &'a mut ::gotham_restful::gotham::state::State,
placeholders: Self::Placeholders,
params: Self::Params,
body: ::std::option::Option<Self::Body>
) -> ::gotham_restful::export::BoxFuture<'static, Self::Output> {
) -> ::gotham_restful::export::BoxFuture<'a, Self::Output> {
#handle_content
}

View file

@ -56,12 +56,12 @@ pub trait Endpoint {
}
/// The handler for this endpoint.
fn handle(
state: &mut State,
fn handle<'a>(
state: &'a mut State,
placeholders: Self::Placeholders,
params: Self::Params,
body: Option<Self::Body>
) -> BoxFuture<'static, Self::Output>;
) -> BoxFuture<'a, Self::Output>;
}
#[cfg(feature = "openapi")]
@ -94,12 +94,12 @@ impl<E: EndpointWithSchema> Endpoint for E {
E::wants_auth()
}
fn handle(
state: &mut State,
fn handle<'a>(
state: &'a mut State,
placeholders: Self::Placeholders,
params: Self::Params,
body: Option<Self::Body>
) -> BoxFuture<'static, Self::Output> {
) -> BoxFuture<'a, Self::Output> {
E::handle(state, placeholders, params, body)
}
}

View file

@ -1,10 +1,15 @@
#[macro_use]
extern crate gotham_derive;
use gotham::{router::builder::*, test::TestServer};
use gotham::{
hyper::{HeaderMap, Method},
router::builder::*,
test::TestServer
};
use gotham_restful::*;
use mime::{APPLICATION_JSON, TEXT_PLAIN};
use serde::Deserialize;
use tokio::time::{delay_for, Duration};
mod util {
include!("util/mod.rs");
@ -12,7 +17,7 @@ mod util {
use util::{test_delete_response, test_get_response, test_post_response, test_put_response};
#[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;
#[derive(Deserialize)]
@ -77,6 +82,15 @@ async fn remove(_id: u64) -> Raw<&'static [u8]> {
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]
fn async_methods() {
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/1", REMOVE_RESPONSE);
test_get_response(&server, "http://localhost/foo/state_test", STATE_TEST_RESPONSE);
}