move signature outside the spawning

this allows us to actually move stuff into the async block
and we can drop the 'static life-time.
This commit is contained in:
Jeb Rosen
2020-02-17 22:34:18 +01:00
committed by Igor Galić
parent a010025074
commit 8aa99cea35
3 changed files with 11 additions and 14 deletions
+5 -5
View File
@@ -10,6 +10,7 @@ use rocket::{data::*, http::Status, response::status, Outcome::*, Request};
use rocket_contrib::json::*;
use serde::Deserialize;
use std::io::Read;
use tokio::io::AsyncReadExt;
pub fn handle_incoming(
rockets: PlumeRocket,
@@ -73,10 +74,7 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
type Owned = String;
type Borrowed = str;
fn transform<'r>(
r: &'r Request,
d: Data
) -> TransformFuture<'r, Self::Owned, Self::Error> {
fn transform<'r>(r: &'r Request, d: Data) -> TransformFuture<'r, Self::Owned, Self::Error> {
Box::pin(async move {
let size_limit = r.limits().get("json").unwrap_or(JSON_LIMIT);
let mut s = String::with_capacity(512);
@@ -96,7 +94,9 @@ impl<'a, T: Deserialize<'a>> FromData<'a> for SignedJson<T> {
let string = try_outcome!(o.borrowed());
match serde_json::from_str(&string) {
Ok(v) => Success(SignedJson(Digest::from_body(&string), Json(v))),
Err(e) if e.is_data() => return Failure((Status::UnprocessableEntity, JsonError::Parse(string, e))),
Err(e) if e.is_data() => {
return Failure((Status::UnprocessableEntity, JsonError::Parse(string, e)))
}
Err(e) => Failure((Status::BadRequest, JsonError::Parse(string, e))),
}
})