mirror of
https://github.com/lov3b/ecb-rates.git
synced 2025-02-22 18:00:11 +01:00
Implement AsRef for table_ref
This commit is contained in:
parent
96aabc8019
commit
3ec57b4414
@ -6,10 +6,10 @@ use super::table_display::helper_table_print;
|
||||
use super::{TableGet, TableTrait};
|
||||
|
||||
pub struct Table {
|
||||
header: Option<String>,
|
||||
column_left: String,
|
||||
column_right: String,
|
||||
rows: Vec<(String, f64)>,
|
||||
pub(super) header: Option<String>,
|
||||
pub(super) column_left: String,
|
||||
pub(super) column_right: String,
|
||||
pub(super) rows: Vec<(String, f64)>,
|
||||
pub color: bool,
|
||||
pub width: usize,
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user