summaryrefslogtreecommitdiff
path: root/src/de.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/de.rs')
-rw-r--r--src/de.rs14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/de.rs b/src/de.rs
index 95208e9..95999d0 100644
--- a/src/de.rs
+++ b/src/de.rs
@@ -4,6 +4,7 @@ use serde::de;
pub use serde::de::value::Error;
use serde::de::value::MapDeserializer;
+use std::io::Read;
use url::form_urlencoded::Parse as UrlEncodedParse;
use url::form_urlencoded::parse;
@@ -45,6 +46,19 @@ pub fn from_str<T: de::Deserialize>(input: &str) -> Result<T, Error> {
from_bytes(input.as_bytes())
}
+/// Convenience function that reads all bytes from `reader` and deserializes
+/// them with `from_bytes`.
+pub fn from_reader<T, R>(mut reader: R) -> Result<T, Error>
+ where T: de::Deserialize, R: Read
+{
+ let mut buf = vec![];
+ reader.read_to_end(&mut buf)
+ .map_err(|e| {
+ de::Error::custom(format_args!("could not read input: {}", e))
+ })?;
+ from_bytes(&buf)
+}
+
/// A deserializer for the `application/x-www-form-urlencoded` format.
///
/// * Supported top-level outputs are structs, maps and sequences of pairs,