pub struct Import { /* private fields */ }Expand description
A CSV file to import; see the module docs.
Implementations§
Source§impl Import
impl Import
Sourcepub fn csv(data: impl AsRef<[u8]>) -> Self
pub fn csv(data: impl AsRef<[u8]>) -> Self
The bytes of a CSV file (an upload’s, a file’s): UTF-8, with or without a byte order mark, its first line naming the columns.
Sourcepub fn delimiter(self, delimiter: char) -> Self
pub fn delimiter(self, delimiter: char) -> Self
Cells are separated by delimiter (; in files from a spreadsheet
set to a European language) instead of ,.
Sourcepub fn headers(self, names: &[&str]) -> Self
pub fn headers(self, names: &[&str]) -> Self
The file has no line of column names: these are its columns, in order.
Sourcepub fn rename(self, heading: &str, field: &str) -> Self
pub fn rename(self, heading: &str, field: &str) -> Self
Reads the column headed heading as the field field, e.g.
rename("Description", "name"). Without one, a heading names its
field in lowercase with _ for spaces and dashes: “Unit price” is
unit_price.
Sourcepub fn max_rows(self, rows: usize) -> Self
pub fn max_rows(self, rows: usize) -> Self
At most rows rows (default MAX_IMPORT_ROWS); a longer file is
refused before anything is written.
Sourcepub fn all_or_nothing(self) -> Self
pub fn all_or_nothing(self) -> Self
Writes nothing unless every row is valid and saved: one bad row and the whole file is refused (the report lists why). By default the good rows are written and the bad ones reported.
Sourcepub fn lang(self, lang: &Lang) -> Self
pub fn lang(self, lang: &Lang) -> Self
Messages (and the report) in this language; the app’s
APP_LOCALE otherwise.
Sourcepub fn user(self, user: &User) -> Self
pub fn user(self, user: &User) -> Self
The user importing, whom the rows’ after hooks see as
form.user (and the current_password rule checks).
Sourcepub fn field(self, name: &str) -> Self
pub fn field(self, name: &str) -> Self
The form field the file came in (file by default): a file that
can’t be read is reported as that field’s error.
Sourcepub fn run<'a, T, F>(
self,
state: &'a AppState,
write: F,
) -> impl Future<Output = Result<ImportReport>> + Send + 'awhere
T: DeserializeOwned + Validate + Send + Sync + 'a,
F: for<'t> FnMut(&'t mut Transaction, T) -> BoxFuture<'t, Result> + Send + 'a,
pub fn run<'a, T, F>(
self,
state: &'a AppState,
write: F,
) -> impl Future<Output = Result<ImportReport>> + Send + 'awhere
T: DeserializeOwned + Validate + Send + Sync + 'a,
F: for<'t> FnMut(&'t mut Transaction, T) -> BoxFuture<'t, Result> + Send + 'a,
Reads every row into a T and checks it with T’s rules (its
prepare and after hooks too), then calls write with each valid
row inside one transaction, a savepoint per row. An error from
write is that row’s failure: a ValidationError shows its
messages, Error::BadRequest its text, a unique-constraint
violation says the row repeats a unique value.
T’s authorize hook isn’t asked: authorize the import’s route.
Auto Trait Implementations§
impl !RefUnwindSafe for Import
impl !UnwindSafe for Import
impl Freeze for Import
impl Send for Import
impl Sync for Import
impl Unpin for Import
impl UnsafeUnpin for Import
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<A, B, T> HttpServerConnExec<A, B> for Twhere
B: Body,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more