some refactoring

This commit is contained in:
Robin Appelman 2025-07-31 20:39:21 +02:00
commit da02bb0329
12 changed files with 237 additions and 111 deletions

View file

@ -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
}