Make Resource::get consume self, for copyless futures

This commit is contained in:
Magnus Hoff 2017-09-01 12:32:30 +02:00
parent 76302353e1
commit 94758adaf4
2 changed files with 4 additions and 7 deletions

View file

@ -86,15 +86,12 @@ impl Resource for ArticleResource {
).boxed()
}
fn get(&self) -> futures::BoxFuture<Response, Box<::std::error::Error + Send>> {
// Accidental clone here:
let data = self.data.clone();
fn get(self) -> futures::BoxFuture<Response, Box<::std::error::Error + Send>> {
self.head().map(move |head|
head
.with_body(Layout {
title: &data.title,
body: &data
title: &self.data.title,
body: &self.data
}.to_string())
).boxed()
}

View file

@ -12,7 +12,7 @@ type Error = Box<std::error::Error + Send>;
pub trait Resource {
fn allow(&self) -> Vec<hyper::Method>;
fn head(&self) -> futures::BoxFuture<server::Response, Error>;
fn get(&self) -> futures::BoxFuture<server::Response, Error>;
fn get(self) -> futures::BoxFuture<server::Response, Error>;
fn options(&self) -> Response {
Response::new()