diff --git a/src/table/table_owned.rs b/src/table/table_owned.rs index 11a92ad..a57ab25 100644 --- a/src/table/table_owned.rs +++ b/src/table/table_owned.rs @@ -6,10 +6,10 @@ use super::table_display::helper_table_print; use super::{TableGet, TableTrait}; pub struct Table { - header: Option, - column_left: String, - column_right: String, - rows: Vec<(String, f64)>, + pub(super) header: Option, + pub(super) column_left: String, + pub(super) column_right: String, + pub(super) rows: Vec<(String, f64)>, pub color: bool, pub width: usize, } diff --git a/src/table/table_ref.rs b/src/table/table_ref.rs index 4e27044..1121244 100644 --- a/src/table/table_ref.rs +++ b/src/table/table_ref.rs @@ -5,6 +5,7 @@ use crate::models::ExchangeRateResult; use super::table_display::helper_table_print; use super::table_getter::TableGet; use super::table_trait::TableTrait; +use super::Table; pub struct TableRef<'a> { header: Option<&'a str>, @@ -90,3 +91,22 @@ impl<'a> Display for TableRef<'a> { helper_table_print(f, self) } } + +impl<'a> From<&'a Table> for TableRef<'a> { + fn from(table: &'a Table) -> Self { + let rows = table + .rows + .iter() + .map(|(left, right)| (left.as_str(), *right)) + .collect(); + + TableRef { + header: table.header.as_deref(), + column_left: table.column_left.as_str(), + column_right: table.column_right.as_str(), + rows, + color: table.color, + width: table.width, + } + } +}