From cff9901940071d8933eacb667ada63fbb430f8a3 Mon Sep 17 00:00:00 2001 From: Sergio Benitez Date: Thu, 30 Mar 2017 23:17:28 -0700 Subject: [PATCH] Implement FromData for Vec. --- lib/src/data/from_data.rs | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/lib/src/data/from_data.rs b/lib/src/data/from_data.rs index ee756269..74afe33a 100644 --- a/lib/src/data/from_data.rs +++ b/lib/src/data/from_data.rs @@ -1,4 +1,4 @@ -use std::io::Read; +use std::io::{self, Read}; use outcome::{self, IntoOutcome}; use outcome::Outcome::*; @@ -184,14 +184,28 @@ impl FromData for Option { } impl FromData for String { - type Error = (); + type Error = io::Error; // FIXME: Doc. fn from_data(_: &Request, data: Data) -> Outcome { let mut string = String::new(); match data.open().read_to_string(&mut string) { Ok(_) => Success(string), - Err(_) => Failure((Status::UnprocessableEntity, ())) + Err(e) => Failure((Status::BadRequest, e)) + } + } +} + +// FIXME Implement this. +impl FromData for Vec { + type Error = io::Error; + + // FIXME: Doc. + fn from_data(_: &Request, data: Data) -> Outcome { + let mut bytes = Vec::new(); + match data.open().read_to_end(&mut bytes) { + Ok(_) => Success(bytes), + Err(e) => Failure((Status::BadRequest, e)) } } }