Use PartialEq/Eq implementation instead of match.

Also cleanup from rebasing onto master.
This commit is contained in:
Mark Story 2016-01-13 20:56:35 -05:00
parent 58410ddd93
commit add80569ff
2 changed files with 13 additions and 27 deletions

View File

@ -9,37 +9,31 @@
// except according to those terms.
use rustfmt_diff::{Mismatch, DiffLine};
use std::io::{self, Write, Read, stdout};
use WriteMode;
use config::WriteMode;
pub fn output_heading(mode: WriteMode) -> Result<(), io::Error> {
let stdout = stdout();
let mut stdout = stdout.lock();
match mode {
WriteMode::Checkstyle => {
let mut xml_heading = String::new();
xml_heading.push_str("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
xml_heading.push_str("\n");
xml_heading.push_str("<checkstyle version=\"4.3\">");
try!(write!(stdout, "{}", xml_heading));
Ok(())
}
_ => Ok(()),
if mode == WriteMode::Checkstyle {
let mut xml_heading = String::new();
xml_heading.push_str("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
xml_heading.push_str("\n");
xml_heading.push_str("<checkstyle version=\"4.3\">");
try!(write!(stdout, "{}", xml_heading));
}
Ok(())
}
pub fn output_footing(mode: WriteMode) -> Result<(), io::Error> {
let stdout = stdout();
let mut stdout = stdout.lock();
match mode {
WriteMode::Checkstyle => {
let mut xml_tail = String::new();
xml_tail.push_str("</checkstyle>");
try!(write!(stdout, "{}", xml_tail));
Ok(())
}
_ => Ok(()),
if mode == WriteMode::Checkstyle {
let mut xml_tail = String::new();
xml_tail.push_str("</checkstyle>");
try!(write!(stdout, "{}", xml_tail));
}
Ok(())
}
pub fn output_checkstyle_file<T>(mut writer: T,

View File

@ -161,14 +161,6 @@ pub fn write_file(text: &StringBuffer,
// Output the XML tags for the lines that are different.
try!(output_checkstyle_file(stdout, filename, diff));
}
WriteMode::Return => {
// io::Write is not implemented for String, working around with
// Vec<u8>
let mut v = Vec::new();
try!(write_system_newlines(&mut v, text, config));
// won't panic, we are writing correct utf8
return Ok(Some(String::from_utf8(v).unwrap()));
}
}
Ok(None)