From f141f8b0430a53fe8e46b72ab452d3fff98a96ea Mon Sep 17 00:00:00 2001 From: Michael Gehring Date: Mon, 3 Nov 2014 17:59:48 +0100 Subject: [PATCH] comm: fix build It's no longer possible to have a Box due to the new object safety rules. Wrap in an enum as a workaround. Fixes #437 --- src/comm/comm.rs | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/comm/comm.rs b/src/comm/comm.rs index 60a2b6beb..505a70a30 100644 --- a/src/comm/comm.rs +++ b/src/comm/comm.rs @@ -14,7 +14,7 @@ extern crate getopts; use std::cmp::Ord; use std::io::{BufferedReader, IoResult, print}; use std::io::fs::File; -use std::io::stdio::stdin; +use std::io::stdio::{stdin, StdReader}; use std::path::Path; static NAME : &'static str = "comm"; @@ -44,7 +44,21 @@ fn ensure_nl(line: String) -> String { } } -fn comm(a: &mut Box, b: &mut Box, opts: &getopts::Matches) { +enum LineReader { + Stdin(BufferedReader), + FileIn(BufferedReader) +} + +impl LineReader { + fn read_line(&mut self) -> IoResult { + match self { + &Stdin(ref mut r) => r.read_line(), + &FileIn(ref mut r) => r.read_line(), + } + } +} + +fn comm(a: &mut LineReader, b: &mut LineReader, opts: &getopts::Matches) { let delim = Vec::from_fn(4, |col| mkdelim(col, opts)); @@ -83,12 +97,12 @@ fn comm(a: &mut Box, b: &mut Box, opts: &getopts::Matches) { } } -fn open_file(name: &str) -> IoResult> { +fn open_file(name: &str) -> IoResult { match name { - "-" => Ok(box stdin() as Box), + "-" => Ok(LineReader::Stdin(stdin())), _ => { - let f = try!(File::open(&Path::new(name))); - Ok(box BufferedReader::new(f) as Box) + let f = try!(std::io::File::open(&Path::new(name))); + Ok(LineReader::FileIn(BufferedReader::new(f))) } } }