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
31
32
33
34
35
36
37
38
39
40
41
use std::fmt;
use serde_json;
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Event {
timestamp: f64,
intensity: f64,
#[serde(skip_serializing_if = "Vec::is_empty")]
children: Vec<Event>
}
impl Event {
pub fn new(timestamp: f64, intensity: f64) -> Event {
Event {
timestamp,
intensity,
children: vec!()
}
}
pub fn add_child(&mut self, par: Event) {
self.children.push(par);
}
pub fn timestamp(&self) -> f64 {
self.timestamp
}
pub fn intensity(&self) -> f64 {
self.intensity
}
}
impl fmt::Display for Event {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let serial_string = serde_json::to_string_pretty(self).unwrap();
write!(f, "{}", serial_string)
}
}