diff options
author | bnewbold <bnewbold@robocracy.org> | 2016-05-29 21:15:05 -0400 |
---|---|---|
committer | bnewbold <bnewbold@robocracy.org> | 2016-05-29 21:15:07 -0400 |
commit | 37fb8945fad0a034d1565bc4f79f9ab524587fc0 (patch) | |
tree | e7dd480223dc1adf093e604839d8bbe943faa0ab /src/common.rs | |
parent | f9b27f5424cb857406a60a2259052dfff1d76439 (diff) | |
download | ucp-37fb8945fad0a034d1565bc4f79f9ab524587fc0.tar.gz ucp-37fb8945fad0a034d1565bc4f79f9ab524587fc0.zip |
genericize common functions over streams
This makes source_files and sink_files generic over "Streams", defined as types
that implement both Read and Write.
Diffstat (limited to 'src/common.rs')
-rw-r--r-- | src/common.rs | 10 |
1 files changed, 3 insertions, 7 deletions
diff --git a/src/common.rs b/src/common.rs index e68bae6..09f2b5b 100644 --- a/src/common.rs +++ b/src/common.rs @@ -1,6 +1,4 @@ -extern crate utp; - use std::str; use std::env; use std::path::Path; @@ -9,10 +7,8 @@ use std::os::unix::fs::PermissionsExt; use std::io; use std::io::{Read, Write, BufRead, BufReader}; use std::process::exit; -use utp::{UtpStream}; - -pub fn source_files(stream: &mut UtpStream, file_path: &str, recursive: bool) { +pub fn source_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) { println!("SOURCE FILE: {}", file_path); if recursive { unimplemented!(); } let mut f = File::open(file_path).unwrap(); @@ -59,7 +55,7 @@ pub fn source_files(stream: &mut UtpStream, file_path: &str, recursive: bool) { }; } -fn raw_read_line(stream: &mut UtpStream) -> io::Result<String> { +fn raw_read_line<S: Read + Write>(stream: &mut S) -> io::Result<String> { let mut s = String::new(); let mut byte_buf = [0]; @@ -75,7 +71,7 @@ fn raw_read_line(stream: &mut UtpStream) -> io::Result<String> { // TODO: it would be nice to be able to do BufReader/BufWriter on UtpStream. This would require // implementations of Read and Write on immutable references to UtpStream (a la TcpStream, File, et // al) -pub fn sink_files(stream: &mut UtpStream, file_path: &str, recursive: bool) { +pub fn sink_files<S: Read + Write>(stream: &mut S, file_path: &str, recursive: bool) { println!("SINK FILE: {}", file_path); if recursive { unimplemented!(); } let mut f = File::create(file_path).unwrap(); |