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
42
43
44
45
46
47
48
49
50
use scsys::prelude::{Event, Timestamp};
use serde::{Deserialize, Serialize};
use std::convert::From;
#[derive(Clone, Debug, Deserialize, Eq, Hash, PartialEq, Serialize)]
pub struct Session {
pub events: Vec<Event>,
pub timestamp: i64,
}
impl Session {
pub fn new(events: Vec<Event>, timestamp: i64) -> Self {
Self { events, timestamp }
}
}
impl From<&Session> for Session {
fn from(data: &Session) -> Self {
data.clone()
}
}
impl From<Vec<Event>> for Session {
fn from(data: Vec<Event>) -> Self {
Self::new(data, Timestamp::default().into())
}
}
impl Default for Session {
fn default() -> Self {
Self::new(Vec::new(), Timestamp::default().into())
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_default_session() {
let a = Session::default();
let b = Session::from(&a);
assert_eq!(&a, &b)
}
}