about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--users/Profpatsch/netencode/netencode.rs14
1 files changed, 13 insertions, 1 deletions
diff --git a/users/Profpatsch/netencode/netencode.rs b/users/Profpatsch/netencode/netencode.rs
index 94327fc5e172..3c6c113df589 100644
--- a/users/Profpatsch/netencode/netencode.rs
+++ b/users/Profpatsch/netencode/netencode.rs
@@ -1,7 +1,7 @@
 extern crate nom;
 
 use std::collections::HashMap;
-use std::io::Write;
+use std::io::{Write, Read};
 
 #[derive(Debug, PartialEq, Eq, Clone)]
 pub enum T {
@@ -116,6 +116,18 @@ pub fn text(s: String) -> T {
     T::Text(s)
 }
 
+pub fn t_from_stdin_or_panic(prog_name: &str) -> T {
+    let mut buf = vec![];
+    std::io::stdin().lock().read_to_end(&mut buf);
+    match parse::t_t(&buf) {
+        Ok((rest, t)) => match rest {
+            b"" => t,
+            _ => panic!("{}: stdin contained some soup after netencode value: {:?}", prog_name, rest)
+        },
+        Err(err) => panic!("{}: unable to parse netencode from stdin: {:?}", prog_name, err)
+    }
+}
+
 pub mod parse {
     use super::{T, Tag, U};