pub struct Exporter { /* private fields */ }Expand description
Main export handler responsible for orchestrating data export operations.
The Exporter struct encapsulates the export format, output destination, and provides methods for exporting different types of data. It handles the complete export pipeline from data gathering to file generation.
§Design Philosophy
The Exporter follows a builder pattern for configuration and uses method dispatch for different export operations. This design provides flexibility while maintaining type safety and clear separation of concerns.
Implementations§
Source§impl Exporter
impl Exporter
Sourcepub fn new(format: ExportFormat, output_path: Option<PathBuf>) -> Self
pub fn new(format: ExportFormat, output_path: Option<PathBuf>) -> Self
Creates a new Exporter instance with specified format and optional output path.
This constructor sets up the export configuration and determines the output file path. If no custom path is provided, it generates a default filename based on the current timestamp and selected format.
§Default File Naming
When no output path is specified, the constructor generates a filename using:
- Prefix: “kasl_export_”
- Timestamp: YYYYMMDD_HHMMSS format
- Extension: Format-appropriate extension (.csv, .json, .xlsx)
Example default names:
kasl_export_20250115_143022.csvkasl_export_20250115_143022.jsonkasl_export_20250115_143022.xlsx
§Path Validation
The constructor validates that:
- Custom paths have appropriate file extensions
- Parent directories exist or can be created
- Write permissions are available
§Arguments
format- The desired export format (CSV, JSON, or Excel)output_path- Optional custom output path; generates default if None
§Returns
Returns a configured Exporter instance ready for export operations.
§Examples
use kasl::libs::export::{Exporter, ExportFormat};
use std::path::PathBuf;
// Create exporter with default filename
let exporter = Exporter::new(ExportFormat::Csv, None);
// Create exporter with custom path
let custom_path = PathBuf::from("reports/daily_report.xlsx");
let exporter = Exporter::new(ExportFormat::Excel, Some(custom_path));Sourcepub fn hourly(self, hourly: bool) -> Self
pub fn hourly(self, hourly: bool) -> Self
Enables or disables the hourly (SiServer-style) daily report layout.
This builder-style method toggles the hourly breakdown rendering for daily reports. It only affects Excel report exports; other formats and data types ignore this flag.
§Arguments
hourly- Whether to render the report as an hourly grid
§Returns
Returns the modified Exporter for method chaining.
Sourcepub async fn export(&self, data_type: ExportData, date: NaiveDate) -> Result<()>
pub async fn export(&self, data_type: ExportData, date: NaiveDate) -> Result<()>
Main export dispatcher that routes to appropriate export handlers based on data type.
This method serves as the primary interface for export operations, determining which specific export handler to invoke based on the requested data type. It provides a unified interface while delegating to specialized methods.
§Export Process Flow
- Data Type Analysis: Determine which export handler to invoke
- Data Gathering: Collect relevant information from the database
- Format Processing: Apply format-specific transformations
- File Generation: Write the formatted data to the output file
- Validation: Verify export completeness and file integrity
§Arguments
data_type- The category of data to export (Report, Tasks, Summary, All)date- The target date for data collection and filtering
§Returns
Returns Ok(()) on successful export completion, or an error if any
step in the export process fails.
§Examples
use kasl::libs::export::{Exporter, ExportFormat, ExportData};
use chrono::NaiveDate;
let exporter = Exporter::new(ExportFormat::Json, None);
let date = NaiveDate::from_ymd_opt(2025, 1, 15).unwrap();
exporter.export(ExportData::Report, date).await?;