Skip to main content

Executor

Struct Executor 

Source
pub struct Executor<T> { /* private fields */ }
Expand description

一个行模型的通用执行器:预览 / 导入 / 导出 / 模板的统一入口

所有方法都基于模型自带的列定义与表名自动构造 runner, 需要微调时再通过 Executor::import_runner / Executor::export_runner 拿到 可配置的 runner(默认值已经可用,一般不需要)。

Implementations§

Source§

impl<T: ExcelRow> Executor<T>

Source

pub fn new(name: &'static str, sheet: Option<&'static str>) -> Self

手动构造(未注册模型也能用;注册模型请用 executor_for)

Source

pub fn name(&self) -> &'static str

Source

pub fn type_name(&self) -> &'static str

Source

pub fn sheet_name(&self) -> Option<&'static str>

Source

pub fn columns(&self) -> &[ColumnDef]

Source

pub fn import_runner(&self) -> ImportRunner

导入 runner(默认 sheets:单模型 = 按 sheet 名,多模型 = All)

会自动套用 executor_config! 注册的模型级配置(合并 / 计算列 / 批大小…)。

Source

pub fn export_runner(&self) -> ExportRunner

导出 runner(列宽 / 格式 / 图片行高来自列定义;并套用模型级导出配置)

Source

pub fn export_runner_for(&self, sheet_name: impl Into<String>) -> ExportRunner

导出 runner(显式指定工作表名)

Source

pub fn template(&self) -> TemplateSpec

导入模板(填入示例行 / 引用列表后交给 build_template)

Source§

impl<T: ExcelRow> Executor<T>

Source

pub fn preview( &self, source: ZipSource, limit: usize, ) -> Result<ImportPreview<T>>
where T: Serialize,

校验预览(不落库,只读前 limit 行)

Source

pub fn preview_json(&self, source: ZipSource, limit: usize) -> Result<Value>
where T: Serialize,

预览转 JSON(按名调度 / HTTP 响应直接返回用)

Source

pub async fn commit<S>( &self, source: ZipSource, sink: Arc<S>, ) -> Result<ImportReport>
where S: BatchSink<T> + ?Sized,

正式导入:流式解析 + 分批落库(解析在阻塞线程,落库走异步任务)

Source

pub fn for_each_row<F>( &self, source: ZipSource, on_row: F, ) -> Result<ImportReport>
where F: FnMut(&RowData<'_>, T) -> Result<(), Vec<String>>,

只解析 + 自定义逐行处理(同步处理,不落库、不攒批)

Source

pub fn export_bytes(&self, rows: &[T]) -> Result<Vec<u8>>

小数据量:写回内存(HTTP 直接下载)

Source

pub fn export_rows<P: AsRef<Path>>(&self, path: P, rows: &[T]) -> Result<u64>

小数据量:写文件

Source

pub fn export_sheets<P: AsRef<Path>>( &self, path: P, named_rows: Vec<(String, Vec<T>)>, ) -> Result<ExportStats>

小数据量:一个文件多张工作表(每张独立数据)

Source

pub async fn export_xlsx<P, F, Fut>( &self, path: P, fetch: F, ) -> Result<ExportStats>
where P: AsRef<Path>, F: FnMut(Option<String>) -> Fut, Fut: Future<Output = Result<Page<T>>> + Send,

游标分批拉取 + 流式写文件(百万行导出推荐)

Source

pub async fn export_multi_sheet<P, F, Fut>( &self, path: P, sheets: Vec<String>, fetch: F, ) -> Result<ExportStats>
where P: AsRef<Path>, F: FnMut(usize, Option<String>) -> Fut, Fut: Future<Output = Result<Page<T>>> + Send,

多工作表游标导出:每张表独立分页拉取,顺序写出

Trait Implementations§

Source§

impl<T: Clone> Clone for Executor<T>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Executor<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T> ErasedExecutor for Executor<T>

Source§

fn name(&self) -> &'static str

Source§

fn type_name(&self) -> &'static str

Source§

fn preview(&self, source: ZipSource, limit: usize) -> Result<Value>

预览前 limit 行并转成 JSON
Source§

fn commit_json<'life0, 'async_trait>( &'life0 self, source: ZipSource, sink: Arc<dyn JsonBatchSink>, ) -> Pin<Box<dyn Future<Output = Result<ImportReport>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

按名导入:解析 source,把每批模型转成 JSON 交给 sink
Source§

fn export_bytes_json(&self, rows: &Value) -> Result<Vec<u8>>

按名导出:从 JSON 行数组(对象数组)生成 xlsx 字节
Source§

fn template(&self) -> TemplateSpec

按名生成导入模板

Auto Trait Implementations§

§

impl<T> Freeze for Executor<T>
where PhantomData<fn() -> T>: Freeze,

§

impl<T> RefUnwindSafe for Executor<T>
where PhantomData<fn() -> T>: RefUnwindSafe,

§

impl<T> Send for Executor<T>
where PhantomData<fn() -> T>: Send,

§

impl<T> Sync for Executor<T>
where PhantomData<fn() -> T>: Sync,

§

impl<T> Unpin for Executor<T>
where PhantomData<fn() -> T>: Unpin,

§

impl<T> UnsafeUnpin for Executor<T>
where PhantomData<fn() -> T>: UnsafeUnpin,

§

impl<T> UnwindSafe for Executor<T>
where PhantomData<fn() -> T>: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.