From 71f37f69c3a4e19fe8e6cf8a56e8c386f795deb2 Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Wed, 6 Jan 2016 19:31:20 +0100 Subject: [PATCH] Move ::new() out of FilePrinter trait --- src/module/notes/mod.rs | 1 - src/ui/file.rs | 28 +++++++++++++++++++--------- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/module/notes/mod.rs b/src/module/notes/mod.rs index e0e107a3..0b445e40 100644 --- a/src/module/notes/mod.rs +++ b/src/module/notes/mod.rs @@ -299,7 +299,6 @@ impl<'a> Notes<'a> { fn command_links(&self, matches: &ArgMatches) -> bool { use ansi_term::Colour::{Red, Green}; use module::helpers::content::markdown::MarkdownParser; - use ui::file::FilePrinter; use util::is_url; use prettytable::Table; use prettytable::row::Row; diff --git a/src/ui/file.rs b/src/ui/file.rs index ce1cd27e..d9151e6c 100644 --- a/src/ui/file.rs +++ b/src/ui/file.rs @@ -10,8 +10,6 @@ use storage::file::File; */ pub trait FilePrinter { - fn new(verbose: bool, debug: bool) -> Self; - /* * Print a single file */ @@ -50,14 +48,18 @@ struct DebugPrinter { debug: bool, } -impl FilePrinter for DebugPrinter { +impl DebugPrinter { - fn new(_: bool, debug: bool) -> DebugPrinter { + pub fn new(debug: bool) -> DebugPrinter { DebugPrinter { debug: debug, } } +} + +impl FilePrinter for DebugPrinter { + fn print_file(&self, f: Rc>) { if self.debug { debug!("[DebugPrinter] ->\n{:?}", f); @@ -82,15 +84,19 @@ struct SimplePrinter { debug: bool, } -impl FilePrinter for SimplePrinter { +impl SimplePrinter { - fn new(verbose: bool, debug: bool) -> SimplePrinter { + pub fn new(verbose: bool, debug: bool) -> SimplePrinter { SimplePrinter { debug: debug, verbose: verbose, } } +} + +impl FilePrinter for SimplePrinter { + fn print_file(&self, f: Rc>) { use ansi_term::Colour::Cyan; @@ -127,14 +133,18 @@ pub struct TablePrinter { sp: SimplePrinter, } -impl FilePrinter for TablePrinter { +impl TablePrinter { - fn new(verbose: bool, debug: bool) -> TablePrinter { + pub fn new(verbose: bool, debug: bool) -> TablePrinter { TablePrinter { - sp: SimplePrinter::new(verbose, debug), + sp: SimplePrinter::new(verbose, debug), } } +} + +impl FilePrinter for TablePrinter { + fn print_file(&self, f: Rc>) { self.sp.print_file(f); }