From 430705439de90327be98d2cc3ae658cdce9edf9f Mon Sep 17 00:00:00 2001 From: Matthias Beyer Date: Thu, 25 Apr 2019 09:54:00 +0200 Subject: Refactor: Add helper for printing table --- src/frontend/table.rs | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/src/frontend/table.rs b/src/frontend/table.rs index 2440161..35c867c 100644 --- a/src/frontend/table.rs +++ b/src/frontend/table.rs @@ -36,6 +36,12 @@ impl TableFrontend { table.set_titles(row!["Name", "Version", "Repo", "Status", "URL"]); table } + + fn print(&self, table: Table) -> Result<()> { + let mut outlock = self.0.lock(); + table.print(&mut outlock)?; + Ok(()) + } } impl Frontend for TableFrontend { @@ -60,11 +66,7 @@ impl Frontend for TableFrontend { table.add_row(row![package.name(), package.version(), package.repo(), status, url]); }); - - let mut outlock = self.0.lock(); - table.print(&mut outlock)?; - - Ok(()) + self.print(table) } fn list_problems(&self, problems: Vec) -> Result<()> { @@ -79,11 +81,7 @@ impl Frontend for TableFrontend { problem.problem_description() ]); }); - - let mut outlock = self.0.lock(); - table.print(&mut outlock)?; - - Ok(()) + self.print(table) } fn compare_packages(&self, packages: Vec, backend: &Backend, filter_repos: Vec) -> Result<()> { @@ -102,11 +100,7 @@ impl Frontend for TableFrontend { ]); }); } - - let mut outlock = self.0.lock(); - table.print(&mut outlock)?; - - Ok(()) + self.print(table) } } -- cgit v1.2.3