/
evcxr.rs
30 lines (26 loc) · 903 Bytes
/
evcxr.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//! This modules contains traits and implementations to work within Evcxr
use super::TableSlice;
use super::utils::StringWriter;
use std::io::Write;
/// Evcxr specific output trait
pub trait EvcxrDisplay {
/// Print self in one or multiple Evcxr compatile types.
fn evcxr_display(&self);
}
impl<'a, T> EvcxrDisplay for T
where
T: AsRef<TableSlice<'a>>,
{
fn evcxr_display(&self) {
let mut writer = StringWriter::new();
// Plain Text
let _ = writer.write_all(b"EVCXR_BEGIN_CONTENT text/plain\n");
let _ = self.as_ref().print(&mut writer);
let _ = writer.write_all(b"\nEVCXR_END_CONTENT\n");
// Html
let _ = writer.write_all(b"EVCXR_BEGIN_CONTENT text/html\n");
let _ = self.as_ref().print_html(&mut writer);
let _ = writer.write_all(b"\nEVCXR_END_CONTENT\n");
println!("{}", writer.as_string());
}
}