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

Fix region errors uncovered by rust-lang/rust#27641 #260

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
fix(lifetimes): correct lifetime pattern to separate out server state…
… from mw state

Correct lifetimes in response to errors found by rust-lang/rust#27641;
the lifetime parameters on request ('a, 'b, 'k) seem to play the
following roles:

'a, 'b -- these represent the processing of this individual request.
They can vary.

'k -- this represents the lifetime of the server's internal, mutable
storage. It is fixed.

If you only have two parameters 'x and 'y to supply, then, the correct
pattern is `'x, 'x, 'y`, because then `'x` plays the role of the
intersection of `'a` and `'b`, but `'y` is pinned to the server's
internal storage.
  • Loading branch information
nikomatsakis committed Aug 14, 2015
commit eeb199253ea702fe645b8d3e7d9d7dd32a889eec
2 changes: 1 addition & 1 deletion src/favicon_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub struct FaviconHandler {
}

impl Middleware for FaviconHandler {
fn invoke<'a, 'b>(&'a self, req: &mut Request<'b, 'a, 'b>, res: Response<'a, net::Fresh>)
fn invoke<'a, 'b>(&'a self, req: &mut Request<'a, 'a, 'b>, res: Response<'a, net::Fresh>)
-> MiddlewareResult<'a> {
if FaviconHandler::is_favicon_request(req) {
self.handle_request(req, res)
Expand Down
2 changes: 1 addition & 1 deletion src/macros/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ macro_rules! _middleware_inner {
#[inline(always)]
fn restrict_closure<F>(f: F) -> F
where F: for<'r, 'b, 'a>
Fn(&'r mut Request<'b, 'a, 'b>, Response<'a>)
Fn(&'r mut Request<'a, 'a, 'b>, Response<'a>)
-> MiddlewareResult<'a> + Send + Sync { f }

restrict_closure(move |as_pat!($req), $res_binding| {
Expand Down
6 changes: 3 additions & 3 deletions src/middleware.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@ pub enum Action<T=(), U=()> {
// the usage of + Send is weird here because what we really want is + Static
// but that's not possible as of today. We have to use + Send for now.
pub trait Middleware: Send + 'static + Sync {
fn invoke<'a, 'b>(&'a self, _req: &mut Request<'b, 'a, 'b>, res: Response<'a, net::Fresh>) -> MiddlewareResult<'a> {
fn invoke<'a, 'b>(&'a self, _req: &mut Request<'a, 'a, 'b>, res: Response<'a, net::Fresh>) -> MiddlewareResult<'a> {
Ok(Continue(res))
}
}

impl<T> Middleware for T where T: for<'r, 'b, 'a> Fn(&'r mut Request<'b, 'a, 'b>, Response<'a>) -> MiddlewareResult<'a> + Send + Sync + 'static {
fn invoke<'a, 'b>(&'a self, req: &mut Request<'b, 'a, 'b>, res: Response<'a>) -> MiddlewareResult<'a> {
impl<T> Middleware for T where T: for<'r, 'b, 'a> Fn(&'r mut Request<'a, 'a, 'b>, Response<'a>) -> MiddlewareResult<'a> + Send + Sync + 'static {
fn invoke<'a, 'b>(&'a self, req: &mut Request<'a, 'a, 'b>, res: Response<'a>) -> MiddlewareResult<'a> {
(*self)(req, res)
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use hyper::server::Request as HyperRequest;
use hyper::uri::RequestUri::AbsolutePath;

///A container for all the request data
pub struct Request<'a, 'b: 'k, 'k: 'a> {
pub struct Request<'a, 'b, 'k: 'a> {
///the original `hyper::server::Request`
pub origin: HyperRequest<'a, 'k>,
///a `HashMap<String, String>` holding all params with names and values
Expand Down
2 changes: 1 addition & 1 deletion src/router/router.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ impl HttpRouter for Router {
}

impl Middleware for Router {
fn invoke<'a, 'b>(&'a self, req: &mut Request<'b, 'a, 'b>, mut res: Response<'a>)
fn invoke<'a, 'b>(&'a self, req: &mut Request<'a, 'a, 'b>, mut res: Response<'a>)
-> MiddlewareResult<'a> {
debug!("Router::invoke for '{:?}'", req.origin.uri);

Expand Down
2 changes: 1 addition & 1 deletion src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ struct ArcServer(Arc<Server>);

impl Handler for ArcServer {
fn handle<'a, 'k>(&'a self, req: Request<'a, 'k>, res: Response<'a>) {
let req: Request<'a, 'k> = req;
let nickel_req = request::Request::from_internal(req);
let nickel_res = response::Response::from_internal(res, &self.0.templates);

self.0.middleware_stack.invoke(nickel_req, nickel_res);
}
}
Expand Down