mirror of
https://codeberg.org/icewind/logsmash.git
synced 2026-06-03 10:04:12 +02:00
some refactoring
This commit is contained in:
parent
14734ad089
commit
da02bb0329
12 changed files with 237 additions and 111 deletions
|
|
@ -6,6 +6,15 @@ use std::borrow::Cow;
|
|||
pub use types::*;
|
||||
use version_compare::{compare, Cmp};
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Ord, PartialOrd, Copy, Hash, Default)]
|
||||
pub struct LogStatementIndex(usize);
|
||||
|
||||
impl From<usize> for LogStatementIndex {
|
||||
fn from(value: usize) -> Self {
|
||||
LogStatementIndex(value)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct StatementList {
|
||||
statements: Vec<(&'static str, &'static [LoggingStatement])>,
|
||||
}
|
||||
|
|
@ -15,21 +24,25 @@ impl StatementList {
|
|||
StatementList { statements }
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> impl Iterator<Item = &'static LoggingStatement> + Send + '_ {
|
||||
pub fn iter(
|
||||
&self,
|
||||
) -> impl Iterator<Item = (LogStatementIndex, &'static LoggingStatement)> + Send + '_ {
|
||||
self.statements
|
||||
.iter()
|
||||
.copied()
|
||||
.flat_map(|(_, list)| list.iter())
|
||||
.enumerate()
|
||||
.map(|(index, statement)| (LogStatementIndex(index), statement))
|
||||
}
|
||||
|
||||
pub fn get(&self, mut index: usize) -> Option<LoggingStatementWithPathPrefix> {
|
||||
pub fn get(&self, mut index: LogStatementIndex) -> Option<LoggingStatementWithPathPrefix> {
|
||||
for (prefix, list) in &self.statements {
|
||||
if index < list.len() {
|
||||
if index.0 < list.len() {
|
||||
return list
|
||||
.get(index)
|
||||
.get(index.0)
|
||||
.map(|statement| statement.with_path_prefix(prefix));
|
||||
}
|
||||
index -= list.len()
|
||||
index.0 -= list.len()
|
||||
}
|
||||
None
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue