mirror of
				https://github.com/lov3b/ecb-rates.git
				synced 2025-10-31 13:20:24 +01:00 
			
		
		
		
	Implement AsRef for table_ref
This commit is contained in:
		| @@ -6,10 +6,10 @@ use super::table_display::helper_table_print; | |||||||
| use super::{TableGet, TableTrait}; | use super::{TableGet, TableTrait}; | ||||||
|  |  | ||||||
| pub struct Table { | pub struct Table { | ||||||
|     header: Option<String>, |     pub(super) header: Option<String>, | ||||||
|     column_left: String, |     pub(super) column_left: String, | ||||||
|     column_right: String, |     pub(super) column_right: String, | ||||||
|     rows: Vec<(String, f64)>, |     pub(super) rows: Vec<(String, f64)>, | ||||||
|     pub color: bool, |     pub color: bool, | ||||||
|     pub width: usize, |     pub width: usize, | ||||||
| } | } | ||||||
|   | |||||||
| @@ -5,6 +5,7 @@ use crate::models::ExchangeRateResult; | |||||||
| use super::table_display::helper_table_print; | use super::table_display::helper_table_print; | ||||||
| use super::table_getter::TableGet; | use super::table_getter::TableGet; | ||||||
| use super::table_trait::TableTrait; | use super::table_trait::TableTrait; | ||||||
|  | use super::Table; | ||||||
|  |  | ||||||
| pub struct TableRef<'a> { | pub struct TableRef<'a> { | ||||||
|     header: Option<&'a str>, |     header: Option<&'a str>, | ||||||
| @@ -90,3 +91,22 @@ impl<'a> Display for TableRef<'a> { | |||||||
|         helper_table_print(f, self) |         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, | ||||||
|  |         } | ||||||
|  |     } | ||||||
|  | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user