laravel-excel 0.3.0

Excel, CSV, ODS, HTML and PDF exports and imports with typed columns for Laravel Rust: a port of Laravel Excel (maatwebsite/excel).
Documentation
//! Laravel Excel's events: `Maatwebsite\Excel\Events`.
//!
//! An export or import receives them through [`WithEvents`](crate::concerns::WithEvents). To
//! listen to every export and import, like `Writer::listen()` and `Sheet::listen()`, register a
//! listener on the provider with the `on_*` methods of [`ExcelServiceProvider`](crate::ExcelServiceProvider), such as [`on_before_export`](crate::ExcelServiceProvider::on_before_export).

use std::collections::BTreeMap;
use std::sync::Arc;

use crate::spreadsheet::{Spreadsheet, Worksheet};

/// `BeforeExport`: the workbook was created, before any sheet is written.
pub struct BeforeExport<'a> {
    /// The workbook: the writer's delegate.
    pub spreadsheet: &'a mut Spreadsheet,
}

/// `BeforeWriting`: the workbook is complete and about to be written to a file.
pub struct BeforeWriting<'a> {
    /// The workbook.
    pub spreadsheet: &'a mut Spreadsheet,
}

/// `BeforeSheet`: a sheet is about to be exported or imported.
pub struct BeforeSheet<'a> {
    /// The sheet: the delegate of Laravel Excel's `Sheet`.
    pub sheet: &'a mut Worksheet,
}

/// `AfterSheet`: a sheet was exported or imported.
pub struct AfterSheet<'a> {
    /// The sheet.
    pub sheet: &'a mut Worksheet,
}

/// `BeforeImport`: the file was opened, before any sheet is read.
pub struct BeforeImport<'a> {
    /// The number of rows of each sheet, by sheet name: `Reader::getTotalRows()`.
    pub total_rows: &'a BTreeMap<String, u32>,
}

/// `AfterImport`: every sheet was read.
pub struct AfterImport<'a> {
    /// The number of rows of each sheet, by sheet name.
    pub total_rows: &'a BTreeMap<String, u32>,
}

/// `AfterBatch`: a batch of `ToModel` rows was saved.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AfterBatch {
    /// The batch size.
    pub batch_size: usize,
    /// The row the batch started at.
    pub start_row: u32,
}

/// `AfterChunk`: a chunk of a `WithChunkReading` import was handled.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct AfterChunk {
    /// The chunk's first row: the offset `RemembersChunkOffset` remembers.
    pub start_row: u32,
}

type Listener<E> = Arc<dyn Fn(&mut E) -> laravel::Result<()> + Send + Sync>;

/// Listeners for every export and import, registered on the provider: `HasEventBus::listen()`.
#[derive(Clone, Default)]
#[allow(clippy::type_complexity)]
pub struct GlobalListeners {
    pub(crate) before_export: Vec<Arc<dyn Fn(&mut BeforeExport<'_>) -> laravel::Result<()> + Send + Sync>>,
    pub(crate) before_writing: Vec<Arc<dyn Fn(&mut BeforeWriting<'_>) -> laravel::Result<()> + Send + Sync>>,
    pub(crate) before_sheet: Vec<Arc<dyn Fn(&mut BeforeSheet<'_>) -> laravel::Result<()> + Send + Sync>>,
    pub(crate) after_sheet: Vec<Arc<dyn Fn(&mut AfterSheet<'_>) -> laravel::Result<()> + Send + Sync>>,
    pub(crate) before_import: Vec<Arc<dyn Fn(&mut BeforeImport<'_>) -> laravel::Result<()> + Send + Sync>>,
    pub(crate) after_import: Vec<Arc<dyn Fn(&mut AfterImport<'_>) -> laravel::Result<()> + Send + Sync>>,
    pub(crate) after_batch: Vec<Listener<AfterBatch>>,
    pub(crate) after_chunk: Vec<Listener<AfterChunk>>,
    pub(crate) import_failed: Vec<Arc<dyn Fn(&laravel::Error) + Send + Sync>>,
}