1
2#[macro_export]
3macro_rules! t {
4 ($($tt:tt)+) => {
5 let timer = std::time::Instant::now();
6 $($tt)+;
7 println!("{:?}", timer.elapsed());
8 }
9}
10
11pub fn type_of<T>(_: &T) {
12 let res = std::any::type_name::<T>();
13 println!("{res}");
14}
15
16use std::fmt::Debug;
17pub trait ForDisplay {
18 fn evcxr_display(&self);
19}
20pub trait ForDisplay2 {
21 fn evcxr_display(&self);
22}
23impl<'a, T> ForDisplay for [&'a [T]]
24where
25 T: Debug,
26{
27 fn evcxr_display(&self) {
28 let mut html = String::new();
29 html.push_str("<table>");
30 for i in 0 .. 50.min(self[0].len()) {
31 html.push_str("<tr>");
32 for j in self.iter() {
33 html.push_str("<td>");
34 html.push_str(&format!("{:?}", j[i]));
35 html.push_str("</td>");
36 }
37 html.push_str("</tr>");
38 }
39 html.push_str("</table>");
40 println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", html);
41 }
42}
43
44impl<T: Debug> ForDisplay for Vec<Vec<T>>
45{
46 fn evcxr_display(&self) {
47 self.iter().map(|x| &x[..]).collect::<Vec<_>>().evcxr_display()
48 }
49}
50
51impl<'a, T> ForDisplay for Vec<&'a [T]>
52where
53 T: Debug,
54{
55 fn evcxr_display(&self) {
56 let mut html = String::new();
57 html.push_str("<table>");
58 for i in 0 .. 50.min(self[0].len()) {
59 html.push_str("<tr>");
60 for j in self.iter() {
61 html.push_str("<td>");
62 html.push_str(&format!("{:?}", j[i]));
63 html.push_str("</td>");
64 }
65 html.push_str("</tr>");
66 }
67 html.push_str("</table>");
68 println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", html);
69 }
70}
71
72impl<T: Debug> ForDisplay2 for [T] {
73 fn evcxr_display(&self) {
74 <[&Self] as ForDisplay>::evcxr_display(&[self])
75 }
76}
77impl<'b, T: Debug, N: Debug> ForDisplay for (Vec<T>, Vec<&'b [N]>) {
78 fn evcxr_display(&self) {
79 let mut html = String::new();
80 html.push_str("<table>");
81 for i in 0 .. 50.min(self.0.len()) {
82 html.push_str("<tr>");
83 html.push_str("<td>");
84 html.push_str(&format!("{:?}", self.0[i]));
85 html.push_str("</td>");
86 for j in 0 .. self.1.len() {
87 html.push_str("<td>");
88 html.push_str(&format!("{:?}", self.1[j][i]));
89 html.push_str("</td>");
90 }
91 html.push_str("</tr>");
92 }
93 html.push_str("</table>");
94 println!("EVCXR_BEGIN_CONTENT text/html\n{}\nEVCXR_END_CONTENT", html);
95 }
96}
97
98pub trait DisplayString {
99 fn dispaly_string(&self) -> String;
100}
101
102impl<T: DisplayString> ForDisplay for T {
103 fn evcxr_display(&self) {
104 println!("{:?}", self.dispaly_string());
105 }
106}
107
108#[macro_export]
109macro_rules! match_trait {
110 ($ta1: ty, $ta2: path) => {
111 fn oll<'a>(data: $ta1) -> impl $ta2 + 'a {
112 data
113 }
114 }
115}