evtc_parse/
lib.rs

1//! Parsing for ArcDPS EVTC logs.
2//!
3//! # Usage
4//! Use the [`parse_file`] function to easily parse a [`Log`] from a file path.
5//! ```no_run
6//! match evtc_parse::parse_file("path/to/log.evtc") {
7//!     Ok(log) => println!("Log for boss id {}", log.header.boss_id),
8//!     Err(err) => eprintln!("Encountered error {}", err),
9//! }
10//! ```
11//!
12//! A [`Log`] can also be parsed from any input implementing [`Read`](io::Read).
13//! ```no_run
14//! use evtc_parse::{Log, Parse};
15//! use std::io;
16//!
17//! fn parse_from_read(input: &mut impl io::Read) -> Log {
18//!     Log::parse(input).expect("failed to parse")
19//! }
20//! ```
21//!
22//! Note that ArcDPS can save compressed log files with `.zevtc` as file extension.
23//! Enabling the `"zevtc"` or `"zip"` feature adds support for compressed logs.
24
25/// Extensions for log EVTC API.
26#[path = "."]
27mod ext {
28    pub mod agent;
29    pub mod event;
30    pub mod skill;
31}
32mod error;
33mod header;
34mod log;
35mod log_transformed;
36mod util;
37
38pub use self::error::*;
39pub use self::ext::agent::*;
40pub use self::ext::skill::*;
41pub use self::header::*;
42pub use self::log::*;
43pub use self::log_transformed::*;
44pub use evtc::*;
45
46#[cfg(feature = "zevtc")]
47mod zip;
48
49#[cfg(feature = "zevtc")]
50pub use self::zip::*;
51
52use std::{io, path::Path};
53
54/// Parses a [`Log`] from a given [`Path`] to a log file.
55///
56/// With the `"zevtc"` or `"zip"` feature enabled this also supports compressed log files.
57pub fn parse_file(path: impl AsRef<Path>) -> Result<Log, ParseError> {
58    Log::parse_file(path)
59}
60
61/// Interface for parsing a value from a [`Read`](io::Read) input.
62pub trait Parse: Sized {
63    /// Associated error which can happen during parsing.
64    type Error;
65
66    /// Parses a value of this type from the input.
67    fn parse(input: &mut impl io::Read) -> Result<Self, Self::Error>;
68
69    /// Parses multiple values of this type from the input into a [`Vec`].
70    fn parse_multi<T>(input: &mut impl io::Read, count: usize) -> Result<T, Self::Error>
71    where
72        T: FromIterator<Self>,
73    {
74        (0..count).map(|_| Self::parse(input)).collect()
75    }
76}
77
78/// Interface for saving a value into a [`Write`](io::Write) output.
79pub trait Save: Sized {
80    /// Associated error which can happen during saving.
81    type Error;
82
83    /// Saves the value to the output.
84    fn save(&self, output: &mut impl io::Write) -> Result<(), Self::Error>;
85}