pub struct FormData<W> { /* private fields */ }
Expand description

multipart/form-data document builder.

See the module documentation for an example.

Implementations

Starts writing a multipart/form-data document to writer.

let mut form = FormData::new(Vec::new());

This generates a nonce as a multipart boundary by combining the current system time with a random string.

Panics

Panics if the random number generator fails or if the current system time is prior to the Unix epoch.

Finish the multipart/form-data document, returning the writer.

let mut form = FormData::new(Vec::new());
// ... things happen ...
let document: Vec<u8> = form.finish()?;
Errors

Returns an error if finish() has already been called or if the writer fails.

Write a non-file field to the document.

form.write_field("butts", "lol")?;
Errors

Returns an error if finish() has already been called or if the writer fails.

Write a file field to the document, copying the data from reader.

RFC 7578 § 4.2 advises “a name for the file SHOULD be supplied”, but “isn’t mandatory for cases where the file name isn’t availbale or is meaningless or private”.

use std::io::Cursor;

const CORRO: &[u8] = include_bytes!("../testdata/corro.svg");
form.write_file("corro", Cursor::new(CORRO), None, "image/svg+xml")?;
Errors

Returns an error if finish() has already been called or if the writer fails.

Write a file field to the document, opening the file at path and copying its data.

This method detects the filename parameter from the path. To avoid this, use FormData::write_file.

form.write_path("corro", "testdata/corro.svg", "image/svg+xml")?;
Errors

Returns an error if finish() has already been called or if the writer fails.

Returns the value of the Content-Type header that corresponds with the document.

// your HTTP client's API may vary
request.with_header("Content-Type", form.content_type_header());

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.

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

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.