fengsp / pencil

A web application microframework for Rust
https://fengsp.github.io/pencil/
Other
872 stars 43 forks source link

Consider consuming Request in handlers #10

Closed justinas closed 8 years ago

justinas commented 8 years ago

Consider the hello world handler:

fn hello(_: &mut Request) -> PencilResult {
    Ok(Response::from("Hello World!"))
}

Is there a reason why the Request instance is taken as a mutable reference, as opposed to consuming it? I am aware Iron does the same, but haven't found a rationale for this.

To me, this:

fn hello(_: Request) -> PencilResult {
    Ok(Response::from("Hello World!"))
}

indicates the intent more clearly: the handler consumes the Request and produces a Result out of it. On the other hand, the current signature indicates that the Request might have some existence after the response has been served (and if it does not, it should be safe to let the handler consume it).

fengsp commented 8 years ago

The framework still need the Request later, at least for now it is.