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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
//! Laravel Excel for Laravel Rust: Excel, CSV and ODS exports and imports.
//!
//! A community port of [Laravel Excel](https://github.com/SpartnerNL/Laravel-Excel)
//! (`maatwebsite/excel` 4.0.7) by Rivervo. See the README for installation and usage.

pub mod columns;
pub mod concerns;
pub mod config;
mod console;
pub mod coordinate;
mod error;
pub mod events;
mod excel;
mod export;
mod fake;
mod html;
mod html_writer;
mod import;
mod number_formatter;
mod other_readers;
mod provider;
mod queue;
mod reader;
mod rich_text;
mod row;
pub mod sheets;
pub mod spreadsheet;
pub mod style;
mod value;
mod writer;
mod xlsx_extras;

pub use config::{CsvExportSettings, CsvImportSettings, ExcelConfig};
pub use error::{ExcelError, Failure, ValidationException};
pub use excel::{
    AsDynExport, AsDynImport, Excel, Exportable, ImportFile, Importable, PendingDownload, PendingImport, PendingQueue,
    PendingQueueImport, PendingRows, PendingStore, Queued, Type,
};
pub use export::{Export, SheetWriter};
pub use fake::ExcelFake;
pub use import::{HeadingRowFormatter, Import, SheetImport, SheetRows, slug};
pub use provider::{Errors, ExcelServiceProvider, Failures, HeadingRowImport};
pub use queue::{QueuedExportJob, QueuedImportJob};
pub use row::{IntoRows, Key, Row};
pub use sheets::{SheetKey, Sheets};
pub use spreadsheet::{Chart, ChartSeries, ChartType, Comment, Drawing, Hyperlink, Spreadsheet, TextRun, Worksheet};
pub use style::{Style, number_format};
pub use value::{
    AdvancedValueBinder, DefaultValueBinder, StringValueBinder, Value, ValueBinder, date_time_to_excel,
    excel_to_date_time,
};
pub use xlsx_extras::ImageContent;

/// What the macros expand to. Not part of the public API.
#[doc(hidden)]
pub mod __private {
    use std::any::Any;
    use std::sync::Arc;

    pub use futures_util::future::BoxFuture;
    pub use inventory;
    pub use laravel::Result;
    pub use serde_json;

    #[cfg(feature = "scout")]
    pub use crate::export::write_scout;
    pub use crate::export::{
        ExportConcerns, SheetWriter, Source, count_query, write_array, write_collection, write_generator,
        write_iterator, write_query,
    };
    pub use crate::import::{
        ImportConcerns, SheetImport, handle_array, handle_collection, handle_each_row, handle_models,
    };
    pub use crate::queue::{QueueableExport, QueueableImport};
    pub use crate::row::into_single_row;
    pub use crate::sheets::Sheet;

    /// Keeps a copy of an export or import for the fake's assertion callbacks, when its type is
    /// `Clone`.
    pub struct Snapshot<'a, T>(pub &'a T);

    pub trait SnapshotClone {
        fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>>;
    }

    impl<T: Clone + Any + Send + Sync> SnapshotClone for Snapshot<'_, T> {
        fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>> {
            Some(Arc::new(self.0.clone()))
        }
    }

    pub trait SnapshotNone {
        fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>>;
    }

    impl<T> SnapshotNone for &Snapshot<'_, T> {
        fn __snapshot(&self) -> Option<Arc<dyn Any + Send + Sync>> {
            None
        }
    }
}

/// Runs the code when the list holds the concern. The first token names the concern.
#[doc(hidden)]
#[macro_export]
macro_rules! __if_has {
    (ToModel; [ToModel $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (ToCollection; [ToCollection $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (ToArray; [ToArray $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (OnEachRow; [OnEachRow $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (WithMapping; [WithMapping $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (WithCustomQuerySize; [WithCustomQuerySize $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (ShouldQueue; [ShouldQueue $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (ShouldQueue; [Queueable $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    (ShouldQueue; [ShouldQueueWithoutChain $(, $rest:ident)*] => { $($code:tt)* }) => { $($code)* };
    ($name:ident; [$other:ident $(, $rest:ident)*] => { $($code:tt)* }) => {
        $crate::__if_has! { $name; [$($rest),*] => { $($code)* } }
    };
    ($name:ident; [] => { $($code:tt)* }) => {};
}

/// Chooses between two pieces of code by whether the list holds the concern.
#[doc(hidden)]
#[macro_export]
macro_rules! __if_has_else {
    (WithMapping; [WithMapping $(, $rest:ident)*] => { $($yes:tt)* } else { $($no:tt)* }) => { $($yes)* };
    (WithCustomQuerySize; [WithCustomQuerySize $(, $rest:ident)*] => { $($yes:tt)* } else { $($no:tt)* }) => { $($yes)* };
    ($name:ident; [$other:ident $(, $rest:ident)*] => { $($yes:tt)* } else { $($no:tt)* }) => {
        $crate::__if_has_else!($name; [$($rest),*] => { $($yes)* } else { $($no)* })
    };
    ($name:ident; [] => { $($yes:tt)* } else { $($no:tt)* }) => { $($no)* };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __export_concern {
    ($s:tt, $c:ident, FromCollection) => {
        $c.source = $crate::__private::Source::Collection;
    };
    ($s:tt, $c:ident, FromArray) => {
        $c.source = $crate::__private::Source::Array;
    };
    ($s:tt, $c:ident, FromIterator) => {
        $c.source = $crate::__private::Source::Iterator;
    };
    ($s:tt, $c:ident, FromGenerator) => {
        $c.source = $crate::__private::Source::Generator;
    };
    ($s:tt, $c:ident, FromQuery) => {
        $c.source = $crate::__private::Source::Query;
    };
    ($s:tt, $c:ident, FromScout) => {
        $c.source = $crate::__private::Source::Scout;
    };
    ($s:tt, $c:ident, FromView) => {
        $c.view = Some($s);
    };
    ($s:tt, $c:ident, WithHeadings) => {
        $c.headings = Some(::std::boxed::Box::new(move || {
            $crate::IntoRows::into_rows($crate::concerns::WithHeadings::headings($s))
        }));
    };
    ($s:tt, $c:ident, WithMapping) => {
        $c.mapping = true;
    };
    ($s:tt, $c:ident, WithColumns) => {
        $c.columns = Some($s);
    };
    ($s:tt, $c:ident, WithCharts) => {
        $c.charts = Some($s);
    };
    ($s:tt, $c:ident, WithExportTemplate) => {
        $c.template = Some($s);
    };
    ($s:tt, $c:ident, WithColumnFormatting) => {
        $c.column_formatting = Some($s);
    };
    ($s:tt, $c:ident, ShouldAutoSize) => {
        let _: &dyn $crate::concerns::ShouldAutoSize = $s;
        $c.should_auto_size = true;
    };
    ($s:tt, $c:ident, WithTitle) => {
        $c.title = Some($s);
    };
    ($s:tt, $c:ident, WithMultipleSheets) => {
        $c.multiple_sheets = Some($s);
    };
    ($s:tt, $c:ident, WithConditionalSheets) => {
        $c.multiple_sheets = Some($s);
    };
    ($s:tt, $c:ident, WithStyles) => {
        $c.styles = Some($s);
    };
    ($s:tt, $c:ident, WithEvents) => {
        $c.events = Some($s);
    };
    ($s:tt, $c:ident, WithCustomStartCell) => {
        $c.start_cell = Some($s);
    };
    ($s:tt, $c:ident, WithStrictNullComparison) => {
        let _: &dyn $crate::concerns::WithStrictNullComparison = $s;
        $c.strict_null_comparison = true;
    };
    ($s:tt, $c:ident, HasReferencesToOtherSheets) => {
        let _: &dyn $crate::concerns::HasReferencesToOtherSheets = $s;
    };
    ($s:tt, $c:ident, WithProperties) => {
        $c.properties = Some($s);
    };
    ($s:tt, $c:ident, WithColumnWidths) => {
        $c.column_widths = Some($s);
    };
    ($s:tt, $c:ident, WithFreezePane) => {
        $c.freeze_pane = Some($s);
    };
    ($s:tt, $c:ident, WithTabColor) => {
        $c.tab_color = Some($s);
    };
    ($s:tt, $c:ident, WithSheetProtection) => {
        $c.sheet_protection = Some($s);
    };
    ($s:tt, $c:ident, WithPageBreaks) => {
        $c.page_breaks = Some($s);
    };
    ($s:tt, $c:ident, WithPrintArea) => {
        $c.print_area = Some($s);
    };
    ($s:tt, $c:ident, WithDrawings) => {
        $c.drawings = Some($s);
    };
    ($s:tt, $c:ident, WithDefaultStyles) => {
        $c.default_styles = Some($s);
    };
    ($s:tt, $c:ident, WithBackgroundColor) => {
        $c.background_color = Some($s);
    };
    ($s:tt, $c:ident, WithCustomValueBinder) => {
        let _: &dyn $crate::concerns::WithCustomValueBinder = $s;
        $c.value_binder = Some($s);
    };
    ($s:tt, $c:ident, WithCustomCsvSettings) => {
        $c.csv_settings = Some($s);
    };
    ($s:tt, $c:ident, WithCustomChunkSize) => {
        $c.chunk_size = Some($s);
    };
    ($s:tt, $c:ident, WithCustomQuerySize) => {};
    ($s:tt, $c:ident, WithPreCalculateFormulas) => {
        let _: &dyn $crate::concerns::WithPreCalculateFormulas = $s;
        $c.pre_calculate_formulas = true;
    };
    ($s:tt, $c:ident, ShouldQueue) => {
        $c.should_queue = Some($s);
    };
    ($s:tt, $c:ident, ShouldBatch) => {
        let _: &dyn $crate::concerns::ShouldBatch = $s;
        $c.should_batch = true;
    };
    ($s:tt, $c:ident, Queueable) => {};
    ($s:tt, $c:ident, $other:ident) => {
        ::core::compile_error!(::core::concat!(
            "`",
            ::core::stringify!($other),
            "` isn't an export concern laravel-excel supports"
        ));
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __export_source {
    ($s:tt, $sheet:ident, $window:ident, [FromCollection $(, $rest:ident)*], $all:tt) => {
        $crate::__private::write_collection($s, $sheet, $crate::__export_mapper!($s, $all)).await
    };
    ($s:tt, $sheet:ident, $window:ident, [FromArray $(, $rest:ident)*], $all:tt) => {
        $crate::__private::write_array($s, $sheet, $crate::__export_mapper!($s, $all)).await
    };
    ($s:tt, $sheet:ident, $window:ident, [FromIterator $(, $rest:ident)*], $all:tt) => {
        $crate::__private::write_iterator($s, $sheet, $crate::__export_mapper!($s, $all)).await
    };
    ($s:tt, $sheet:ident, $window:ident, [FromGenerator $(, $rest:ident)*], $all:tt) => {
        $crate::__private::write_generator($s, $sheet, $crate::__export_mapper!($s, $all)).await
    };
    ($s:tt, $sheet:ident, $window:ident, [FromQuery $(, $rest:ident)*], $all:tt) => {
        $crate::__private::write_query($s, $sheet, $window, $crate::__export_mapper!($s, $all)).await
    };
    ($s:tt, $sheet:ident, $window:ident, [FromScout $(, $rest:ident)*], $all:tt) => {
        $crate::__private::write_scout($s, $sheet, $crate::__export_mapper!($s, $all)).await
    };
    ($s:tt, $sheet:ident, $window:ident, [$other:ident $(, $rest:ident)*], $all:tt) => {
        $crate::__export_source!($s, $sheet, $window, [$($rest),*], $all)
    };
    ($s:tt, $sheet:ident, $window:ident, [], $all:tt) => {
        ::core::result::Result::Ok(())
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __export_mapper {
    ($s:tt, [$($all:ident),*]) => {
        $crate::__if_has_else!(WithMapping; [$($all),*] => {
            |row| $crate::concerns::WithMapping::map($s, row)
        } else {
            |row| row
        })
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __export_count {
    ($s:tt, [FromQuery $(, $rest:ident)*], [$($all:ident),*]) => {
        $crate::__if_has_else!(WithCustomQuerySize; [$($all),*] => {
            ::core::result::Result::Ok(::core::option::Option::Some(
                $crate::concerns::WithCustomQuerySize::query_size($s).await?,
            ))
        } else {
            ::core::result::Result::Ok(::core::option::Option::Some($crate::__private::count_query($s).await?))
        })
    };
    ($s:tt, [$other:ident $(, $rest:ident)*], $all:tt) => {
        $crate::__export_count!($s, [$($rest),*], $all)
    };
    ($s:tt, [], $all:tt) => {
        ::core::result::Result::Ok(::core::option::Option::None)
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __snapshot_and_name {
    ($ty:ty) => {
        fn __type_name(&self) -> &'static str {
            ::core::any::type_name::<$ty>()
        }

        fn __snapshot(
            &self,
        ) -> ::core::option::Option<::std::sync::Arc<dyn ::core::any::Any + ::core::marker::Send + ::core::marker::Sync>> {
            #[allow(unused_imports)]
            use $crate::__private::{SnapshotClone as _, SnapshotNone as _};
            (&$crate::__private::Snapshot(self)).__snapshot()
        }
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __queue_payload {
    ($ty:ty; $all:tt) => {
        $crate::__if_has! { ShouldQueue; $all => {
            fn __queue_payload(
                &self,
            ) -> ::core::option::Option<$crate::__private::Result<(&'static str, $crate::__private::serde_json::Value)>> {
                ::core::option::Option::Some(
                    $crate::__private::serde_json::to_value(self)
                        .map(|value| (::core::concat!(::core::module_path!(), "::", ::core::stringify!($ty)), value))
                        .map_err(::core::convert::Into::into),
                )
            }
        } }
    };
}

/// Declares an export's concerns: implements [`Export`] for the type from the
/// [concerns](crate::concerns) it lists, like the interfaces a PHP export implements.
///
/// ```ignore
/// laravel_excel::export!(UsersExport: FromQuery, WithHeadings, WithMapping, ShouldAutoSize);
/// ```
///
/// Each listed concern's trait must be implemented, including the marker concerns such as
/// `ShouldAutoSize` (`impl ShouldAutoSize for UsersExport {}`). List `Queueable` to let
/// [`Excel::queue`] queue the export, and `ShouldQueue` to make [`Excel::store`] queue it; both
/// need the export to implement `Serialize` and `Deserialize`.
#[macro_export]
macro_rules! export {
    ($ty:ty : $($concern:ident),* $(,)?) => {
        impl $crate::Export for $ty {
            fn __concerns(&self) -> $crate::__private::ExportConcerns<'_> {
                #[allow(unused_mut)]
                let mut concerns = $crate::__private::ExportConcerns::default();
                $( $crate::__export_concern!(self, concerns, $concern); )*
                concerns
            }

            fn __write<'a>(
                &'a self,
                sheet: &'a mut $crate::__private::SheetWriter<'_>,
                window: ::core::option::Option<(u64, u64)>,
            ) -> $crate::__private::BoxFuture<'a, $crate::__private::Result<()>> {
                ::std::boxed::Box::pin(async move {
                    let _ = (&sheet, &window);
                    $crate::__export_source!(self, sheet, window, [$($concern),*], [$($concern),*])
                })
            }

            fn __count(&self) -> $crate::__private::BoxFuture<'_, $crate::__private::Result<::core::option::Option<u64>>> {
                ::std::boxed::Box::pin(async move {
                    $crate::__export_count!(self, [$($concern),*], [$($concern),*])
                })
            }

            $crate::__snapshot_and_name!($ty);

            $crate::__queue_payload!($ty; [$($concern),*]);
        }

        impl $crate::sheets::IntoSheet for $ty {
            fn into_sheet(self) -> $crate::__private::Sheet {
                $crate::__private::Sheet::Export(::std::boxed::Box::new(self))
            }
        }

        $crate::__if_has! { ShouldQueue; [$($concern),*] => {
            $crate::__private::inventory::submit! {
                $crate::__private::QueueableExport {
                    name: ::core::concat!(::core::module_path!(), "::", ::core::stringify!($ty)),
                    restore: {
                        fn restore(
                            value: $crate::__private::serde_json::Value,
                        ) -> $crate::__private::Result<::std::boxed::Box<dyn $crate::Export>> {
                            ::core::result::Result::Ok(::std::boxed::Box::new(
                                $crate::__private::serde_json::from_value::<$ty>(value)?,
                            ))
                        }
                        restore
                    },
                }
            }
        } }
    };
}

#[doc(hidden)]
#[macro_export]
macro_rules! __import_concern {
    ($s:tt, $c:ident, ToModel) => {};
    ($s:tt, $c:ident, ToCollection) => {};
    ($s:tt, $c:ident, ToArray) => {};
    ($s:tt, $c:ident, OnEachRow) => {};
    ($s:tt, $c:ident, WithHeadingRow) => {
        $c.heading_row = Some($s);
    };
    ($s:tt, $c:ident, WithGroupedHeadingRow) => {
        let _: &dyn $crate::concerns::WithGroupedHeadingRow = $s;
        $c.heading_row = Some($s);
        $c.grouped_heading_row = true;
    };
    ($s:tt, $c:ident, WithStartRow) => {
        $c.start_row = Some($s);
    };
    ($s:tt, $c:ident, WithLimit) => {
        $c.limit = Some($s);
    };
    ($s:tt, $c:ident, WithColumnLimit) => {
        $c.column_limit = Some($s);
    };
    ($s:tt, $c:ident, WithMappedCells) => {
        $c.mapped_cells = Some($s);
    };
    ($s:tt, $c:ident, WithMapping) => {
        $c.mapping = Some(::std::boxed::Box::new(move |row: $crate::Row| {
            $crate::__private::into_single_row(<Self as $crate::concerns::WithMapping<$crate::Row>>::map($s, row))
        }));
    };
    ($s:tt, $c:ident, WithValidation) => {
        $c.validation = Some($s);
    };
    ($s:tt, $c:ident, SkipsOnFailure) => {
        $c.skips_on_failure = Some($s);
    };
    ($s:tt, $c:ident, SkipsOnError) => {
        $c.skips_on_error = Some($s);
    };
    ($s:tt, $c:ident, SkipsEmptyRows) => {
        $c.skips_empty_rows = Some($s);
    };
    ($s:tt, $c:ident, SkipsUnknownSheets) => {
        $c.skips_unknown_sheets = Some($s);
    };
    ($s:tt, $c:ident, WithCalculatedFormulas) => {
        let _: &dyn $crate::concerns::WithCalculatedFormulas = $s;
        $c.calculated_formulas = true;
    };
    ($s:tt, $c:ident, WithColumns) => {
        $c.columns = Some($s);
    };
    ($s:tt, $c:ident, WithFormatData) => {
        let _: &dyn $crate::concerns::WithFormatData = $s;
        $c.format_data = true;
    };
    ($s:tt, $c:ident, WithSkipDuplicates) => {
        let _: &dyn $crate::concerns::WithSkipDuplicates = $s;
        $c.skip_duplicates = true;
    };
    ($s:tt, $c:ident, WithReadFilter) => {
        $c.read_filter = Some($s);
    };
    ($s:tt, $c:ident, WithProgressBar) => {
        $c.progress_bar = Some($s);
    };
    ($s:tt, $c:ident, WithStrictNullComparison) => {
        let _: &dyn $crate::concerns::WithStrictNullComparison = $s;
        $c.strict_null_comparison = true;
    };
    ($s:tt, $c:ident, WithEvents) => {
        $c.events = Some($s);
    };
    ($s:tt, $c:ident, WithCustomCsvSettings) => {
        $c.csv_settings = Some($s);
    };
    ($s:tt, $c:ident, WithCustomValueBinder) => {
        let _: &dyn $crate::concerns::WithCustomValueBinder = $s;
        $c.value_binder = Some($s);
    };
    ($s:tt, $c:ident, WithMultipleSheets) => {
        $c.multiple_sheets = Some($s);
    };
    ($s:tt, $c:ident, WithConditionalSheets) => {
        $c.multiple_sheets = Some($s);
    };
    ($s:tt, $c:ident, WithBatchInserts) => {
        $c.batch_inserts = Some($s);
    };
    ($s:tt, $c:ident, WithChunkReading) => {
        $c.chunk_reading = Some($s);
    };
    ($s:tt, $c:ident, WithUpserts) => {
        $c.upserts = Some($s);
    };
    ($s:tt, $c:ident, WithUpsertColumns) => {
        $c.upsert_columns = Some($s);
    };
    ($s:tt, $c:ident, ShouldQueue) => {
        $c.should_queue = Some($s);
    };
    ($s:tt, $c:ident, ShouldBatch) => {
        let _: &dyn $crate::concerns::ShouldBatch = $s;
        $c.should_batch = true;
    };
    ($s:tt, $c:ident, ShouldQueueWithoutChain) => {
        $c.should_queue = Some($s);
        $c.without_chain = Some($s);
    };
    ($s:tt, $c:ident, RemembersRowNumber) => {
        let _: &dyn $crate::concerns::RemembersRowNumber = $s;
    };
    ($s:tt, $c:ident, RemembersChunkOffset) => {
        let _: &dyn $crate::concerns::RemembersChunkOffset = $s;
    };
    ($s:tt, $c:ident, Queueable) => {};
    ($s:tt, $c:ident, $other:ident) => {
        ::core::compile_error!(::core::concat!(
            "`",
            ::core::stringify!($other),
            "` isn't an import concern laravel-excel supports"
        ));
    };
}

/// Declares an import's concerns: implements [`Import`] for the type from the
/// [concerns](crate::concerns) it lists.
///
/// ```ignore
/// laravel_excel::import!(UsersImport: ToModel, WithHeadingRow, WithBatchInserts, WithValidation);
/// ```
///
/// Each listed concern's trait must be implemented. `ShouldQueue` (with `WithChunkReading`)
/// queues the import's chunks, and needs the import to implement `Serialize` and `Deserialize`.
#[macro_export]
macro_rules! import {
    ($ty:ty : $($concern:ident),* $(,)?) => {
        impl $crate::Import for $ty {
            fn __concerns(&self) -> $crate::__private::ImportConcerns<'_> {
                #[allow(unused_mut)]
                let mut concerns = $crate::__private::ImportConcerns::default();
                $( $crate::__import_concern!(self, concerns, $concern); )*
                concerns
            }

            fn __handle<'a>(
                &'a self,
                sheet: &'a $crate::__private::SheetImport<'a>,
            ) -> $crate::__private::BoxFuture<'a, $crate::__private::Result<()>> {
                ::std::boxed::Box::pin(async move {
                    let _ = &sheet;
                    $crate::__if_has!(ToModel; [$($concern),*] => {
                        $crate::__private::handle_models(self, sheet).await?;
                    });
                    $crate::__if_has!(ToCollection; [$($concern),*] => {
                        $crate::__private::handle_collection(self, sheet).await?;
                    });
                    $crate::__if_has!(ToArray; [$($concern),*] => {
                        $crate::__private::handle_array(self, sheet).await?;
                    });
                    $crate::__if_has!(OnEachRow; [$($concern),*] => {
                        $crate::__private::handle_each_row(self, sheet).await?;
                    });
                    ::core::result::Result::Ok(())
                })
            }

            $crate::__snapshot_and_name!($ty);

            $crate::__queue_payload!($ty; [$($concern),*]);
        }

        impl $crate::sheets::IntoSheet for $ty {
            fn into_sheet(self) -> $crate::__private::Sheet {
                $crate::__private::Sheet::Import(::std::boxed::Box::new(self))
            }
        }

        $crate::__if_has! { ShouldQueue; [$($concern),*] => {
            $crate::__private::inventory::submit! {
                $crate::__private::QueueableImport {
                    name: ::core::concat!(::core::module_path!(), "::", ::core::stringify!($ty)),
                    restore: {
                        fn restore(
                            value: $crate::__private::serde_json::Value,
                        ) -> $crate::__private::Result<::std::boxed::Box<dyn $crate::Import>> {
                            ::core::result::Result::Ok(::std::boxed::Box::new(
                                $crate::__private::serde_json::from_value::<$ty>(value)?,
                            ))
                        }
                        restore
                    },
                }
            }
        } }
    };
}