evtc_parse/
log_transformed.rs
1use crate::{Agent, EventKind, Header, Log, Parse, ParseError, Skill};
2use std::io;
3
4#[cfg(feature = "serde")]
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone)]
9#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
10pub struct LogTransformed {
11 pub header: Header,
13
14 pub agents: Vec<Agent>,
16
17 pub skills: Vec<Skill>,
19
20 pub events: Vec<EventKind>,
22}
23
24impl LogTransformed {
25 #[inline]
27 pub fn agent(&self, id: u64) -> Option<&Agent> {
28 self.agents.iter().find(|agent| agent.id == id)
29 }
30
31 #[inline]
33 pub fn agent_mut(&mut self, id: u64) -> Option<&mut Agent> {
34 self.agents.iter_mut().find(|agent| agent.id == id)
35 }
36
37 #[inline]
39 pub fn agent_name(&self, id: u64) -> Option<&[String]> {
40 self.agent(id).map(|agent| agent.name.as_slice())
41 }
42
43 #[inline]
45 pub fn skill(&self, id: u32) -> Option<&Skill> {
46 self.skills.iter().find(|skill| skill.id == id)
47 }
48
49 #[inline]
51 pub fn skill_mut(&mut self, id: u32) -> Option<&mut Skill> {
52 self.skills.iter_mut().find(|skill| skill.id == id)
53 }
54
55 #[inline]
57 pub fn skill_name(&self, id: u32) -> Option<&str> {
58 self.skill(id).map(|skill| skill.name.as_str())
59 }
60}
61
62impl From<Log> for LogTransformed {
63 #[inline]
64 fn from(log: Log) -> Self {
65 Self {
66 header: log.header,
67 agents: log.agents,
68 skills: log.skills,
69 events: log
70 .events
71 .into_iter()
72 .map(|event| event.into_kind())
73 .collect(),
74 }
75 }
76}
77
78impl Parse for LogTransformed {
79 type Error = ParseError;
80
81 fn parse(input: &mut impl io::Read) -> Result<Self, Self::Error> {
82 Log::parse(input).map(Into::into)
83 }
84}