From 5bc1ddb64d36ae3d82ef1b8f459868639600da59 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Tue, 23 Aug 2022 13:22:56 +0200 Subject: [PATCH] move enum to other file --- src/timetable/models.rs | 52 ----------------------------------------- src/utils.rs | 31 +++++++++++------------- src/utils/models.rs | 51 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 70 deletions(-) create mode 100644 src/utils/models.rs diff --git a/src/timetable/models.rs b/src/timetable/models.rs index a62f476..1b67bcf 100644 --- a/src/timetable/models.rs +++ b/src/timetable/models.rs @@ -33,55 +33,3 @@ pub struct Day { /// Ordered list of all the courses of the day pub courses: Vec>, } - -/// Collection of char for the table -pub enum TabChar { - /// Vertical bar - Bv, - /// Horizontal bar - Bh, - /// Joint left - Jl, - /// Joint right - Jr, - /// Joint bottom left - Jbl, - /// Joint bottom right - Jbr, - /// Joint top left - Jtl, - /// Joint top right - Jtr, - /// Joint to top - Jtt, - /// Joint to bottom - Jtb, - /// Joint of the middle - Jm, -} - -impl TabChar { - /// Value of the element - pub fn val(&self) -> char { - match *self { - Self::Bv => '│', - Self::Bh => '─', - Self::Jl => '├', - Self::Jr => '┤', - Self::Jbl => '└', - Self::Jbr => '┘', - Self::Jtl => '┌', - Self::Jtr => '┐', - Self::Jtt => '┴', - Self::Jtb => '┬', - Self::Jm => '┼', - } - } -} - -/// Position for lines inside the table -pub enum Position { - Top, - Middle, - Bottom -} diff --git a/src/utils.rs b/src/utils.rs index 46a0c95..ca77faa 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,4 @@ -use crate::timetable::models::{Position, TabChar}; +pub mod models; /// Panic if an error happened pub fn check_errors(html: &String, loc: &str) { @@ -22,42 +22,37 @@ fn err_code(code: i32) -> String { /// - 0 -> top of the table /// - 1 -> middle of the table /// - 2 -> bottom of the table -pub fn line_table(cell_length: usize, number_cell: usize, pos: Position) { +pub fn line_table(cell_length: usize, number_cell: usize, pos: models::Position) { let err_msg = "Unknown position"; // Left side let ls = match pos { - Position::Top => TabChar::Jtl.val(), - Position::Middle => TabChar::Jl.val(), - Position::Bottom => TabChar::Jbl.val(), + models::Position::Top => models::TabChar::Jtl.val(), + models::Position::Middle => models::TabChar::Jl.val(), + models::Position::Bottom => models::TabChar::Jbl.val(), _ => panic!("{}", err_msg), }; // Middle let ms = match pos { - Position::Top => TabChar::Jtb.val(), - Position::Middle => TabChar::Jm.val(), - Position::Bottom => TabChar::Jtt.val(), + models::Position::Top => models::TabChar::Jtb.val(), + models::Position::Middle => models::TabChar::Jm.val(), + models::Position::Bottom => models::TabChar::Jtt.val(), _ => panic!("{}", err_msg), }; // Right side let rs = match pos { - Position::Top => TabChar::Jtr.val(), - Position::Middle => TabChar::Jr.val(), - Position::Bottom => TabChar::Jbr.val(), + models::Position::Top => models::TabChar::Jtr.val(), + models::Position::Middle => models::TabChar::Jr.val(), + models::Position::Bottom => models::TabChar::Jbr.val(), _ => panic!("{}", err_msg), }; - let line = TabChar::Bh.val().to_string().repeat(cell_length); + let line = models::TabChar::Bh.val().to_string().repeat(cell_length); // Print the line - print!( - "\n{}{}{}", - ls, - line, - ms - ); + print!("\n{}{}{}", ls, line, ms); for _ in 2..number_cell { print!("{}{}", line, ms); } diff --git a/src/utils/models.rs b/src/utils/models.rs new file mode 100644 index 0000000..5d00157 --- /dev/null +++ b/src/utils/models.rs @@ -0,0 +1,51 @@ +/// Collection of char for the table +pub enum TabChar { + /// Vertical bar + Bv, + /// Horizontal bar + Bh, + /// Joint left + Jl, + /// Joint right + Jr, + /// Joint bottom left + Jbl, + /// Joint bottom right + Jbr, + /// Joint top left + Jtl, + /// Joint top right + Jtr, + /// Joint to top + Jtt, + /// Joint to bottom + Jtb, + /// Joint of the middle + Jm, +} + +impl TabChar { + /// Value of the element + pub fn val(&self) -> char { + match *self { + Self::Bv => '│', + Self::Bh => '─', + Self::Jl => '├', + Self::Jr => '┤', + Self::Jbl => '└', + Self::Jbr => '┘', + Self::Jtl => '┌', + Self::Jtr => '┐', + Self::Jtt => '┴', + Self::Jtb => '┬', + Self::Jm => '┼', + } + } +} + +/// Position for lines inside the table +pub enum Position { + Top, + Middle, + Bottom +}