use crate::snapshot::MemorySnapshot;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OutputFormat {
Json,
Html,
Binary,
Csv,
Svg,
}
impl fmt::Display for OutputFormat {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
OutputFormat::Json => write!(f, "json"),
OutputFormat::Html => write!(f, "html"),
OutputFormat::Binary => write!(f, "binary"),
OutputFormat::Csv => write!(f, "csv"),
OutputFormat::Svg => write!(f, "svg"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RenderConfig {
pub format: OutputFormat,
pub output_path: Option<String>,
pub verbose: bool,
pub include_timestamps: bool,
}
impl Default for RenderConfig {
fn default() -> Self {
Self {
format: OutputFormat::Json,
output_path: None,
verbose: false,
include_timestamps: true,
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RenderResult {
pub data: Vec<u8>,
pub format: OutputFormat,
pub size: usize,
}
pub trait Renderer: Send + Sync {
fn format(&self) -> OutputFormat;
fn render(
&self,
snapshot: &MemorySnapshot,
config: &RenderConfig,
) -> Result<RenderResult, String>;
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_output_format_display() {
assert_eq!(OutputFormat::Json.to_string(), "json");
assert_eq!(OutputFormat::Html.to_string(), "html");
assert_eq!(OutputFormat::Binary.to_string(), "binary");
}
#[test]
fn test_render_config_default() {
let config = RenderConfig::default();
assert_eq!(config.format, OutputFormat::Json);
assert!(!config.verbose);
assert!(config.include_timestamps);
}
}