pumpkin_solver/statistics/
mod.rspub(crate) mod statistic_logger;
pub(crate) mod statistic_logging;
use std::fmt::Display;
use std::fmt::Write;
pub use statistic_logger::StatisticLogger;
pub use statistic_logging::configure_statistic_logging;
pub use statistic_logging::log_statistic;
pub use statistic_logging::log_statistic_postfix;
pub use statistic_logging::should_log_statistics;
pub use statistic_logging::StatisticOptions;
#[cfg(doc)]
use crate::create_statistics_struct;
#[cfg(doc)]
use crate::Solver;
pub trait Statistic {
fn log(&self, statistic_logger: StatisticLogger);
}
impl<Value: Display> Statistic for Value {
fn log(&self, mut statistic_logger: StatisticLogger) {
write!(statistic_logger, "{self}").expect("Expected statistic to be logged");
}
}
#[macro_export]
macro_rules! create_statistics_struct {
($(#[$struct_documentation:meta])* $name:ident { $($(#[$variable_documentation:meta])* $field:ident : $type:ident),+ $(,)? }) => {
$(#[$struct_documentation])*
#[derive(Default, Debug, Copy, Clone)]
pub(crate) struct $name {
$($(#[$variable_documentation])* pub(crate) $field: $type),+
}
impl $crate::statistics::Statistic for $name {
fn log(&self, statistic_logger: $crate::statistics::StatisticLogger) {
$(self.$field.log(statistic_logger.attach_to_prefix(stringify!($field),)));+
}
}
};
}