pub struct Form<'a> { /* private fields */ }
Expand description
Implements the multipart/form-data media type as described by RFC 7578.
See.
Implementations
impl<'a> Form<'a>
impl<'a> Form<'a>
pub fn new<G>() -> Form<'a> where
G: BoundaryGenerator,
pub fn new<G>() -> Form<'a> where
G: BoundaryGenerator,
Creates a new form with the specified boundary generator function.
Examples
struct TestGenerator;
impl BoundaryGenerator for TestGenerator {
fn generate_boundary() -> String {
"test".to_string()
}
}
let form = multipart::Form::new::<TestGenerator>();
pub fn add_text<N, T>(&mut self, name: N, text: T) where
N: Display,
T: Into<String>,
pub fn add_text<N, T>(&mut self, name: N, text: T) where
N: Display,
T: Into<String>,
Adds a text part to the Form.
Examples
use common_multipart_rfc7578::client::multipart;
let mut form = multipart::Form::default();
form.add_text("text", "Hello World!");
form.add_text("more", String::from("Hello Universe!"));
pub fn add_reader<F, R>(&mut self, name: F, read: R) where
F: Display,
R: 'a + Read + Send + Sync + Unpin,
pub fn add_reader<F, R>(&mut self, name: F, read: R) where
F: Display,
R: 'a + Read + Send + Sync + Unpin,
Adds a readable part to the Form.
Examples
use common_multipart_rfc7578::client::multipart;
use std::io::Cursor;
let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();
form.add_reader("input", bytes);
pub fn add_async_reader<F, R>(&mut self, name: F, read: R) where
F: Display,
R: 'a + AsyncRead + Send + Sync + Unpin,
pub fn add_async_reader<F, R>(&mut self, name: F, read: R) where
F: Display,
R: 'a + AsyncRead + Send + Sync + Unpin,
Adds a readable part to the Form.
Examples
use common_multipart_rfc7578::client::multipart;
use futures_util::io::Cursor;
let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();
form.add_async_reader("input", bytes);
pub fn add_file<P, F>(&mut self, name: F, path: P) -> Result<(), Error> where
P: AsRef<Path>,
F: Display,
pub fn add_file<P, F>(&mut self, name: F, path: P) -> Result<(), Error> where
P: AsRef<Path>,
F: Display,
Adds a file, and attempts to derive the mime type.
Examples
use common_multipart_rfc7578::client::multipart;
let mut form = multipart::Form::default();
form.add_file("file", file!()).expect("file to exist");
pub fn add_file_with_mime<P, F>(
&mut self,
name: F,
path: P,
mime: Mime
) -> Result<(), Error> where
P: AsRef<Path>,
F: Display,
pub fn add_file_with_mime<P, F>(
&mut self,
name: F,
path: P,
mime: Mime
) -> Result<(), Error> where
P: AsRef<Path>,
F: Display,
Adds a file with the specified mime type to the form. If the mime type isn’t specified, a mime type will try to be derived.
Examples
use common_multipart_rfc7578::client::multipart;
let mut form = multipart::Form::default();
form.add_file_with_mime("data", "test.csv", mime::TEXT_CSV);
pub fn add_reader_file<F, G, R>(&mut self, name: F, read: R, filename: G) where
F: Display,
G: Into<String>,
R: 'a + Read + Send + Sync + Unpin,
pub fn add_reader_file<F, G, R>(&mut self, name: F, read: R, filename: G) where
F: Display,
G: Into<String>,
R: 'a + Read + Send + Sync + Unpin,
Adds a readable part to the Form as a file.
Examples
use common_multipart_rfc7578::client::multipart;
use std::io::Cursor;
let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();
form.add_reader_file("input", bytes, "filename.txt");
pub fn add_async_reader_file<F, G, R>(&mut self, name: F, read: R, filename: G) where
F: Display,
G: Into<String>,
R: 'a + AsyncRead + Send + Sync + Unpin,
pub fn add_async_reader_file<F, G, R>(&mut self, name: F, read: R, filename: G) where
F: Display,
G: Into<String>,
R: 'a + AsyncRead + Send + Sync + Unpin,
Adds a readable part to the Form as a file.
Examples
use common_multipart_rfc7578::client::multipart;
use futures_util::io::Cursor;
let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();
form.add_async_reader_file("input", bytes, "filename.txt");
pub fn add_reader_file_with_mime<F, G, R>(
&mut self,
name: F,
read: R,
filename: G,
mime: Mime
) where
F: Display,
G: Into<String>,
R: 'a + Read + Send + Sync + Unpin,
pub fn add_reader_file_with_mime<F, G, R>(
&mut self,
name: F,
read: R,
filename: G,
mime: Mime
) where
F: Display,
G: Into<String>,
R: 'a + Read + Send + Sync + Unpin,
Adds a readable part to the Form as a file with a specified mime.
Examples
use common_multipart_rfc7578::client::multipart;
use std::io::Cursor;
let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();
form.add_reader_file_with_mime("input", bytes, "filename.txt", mime::TEXT_PLAIN);
pub fn add_async_reader_file_with_mime<F, G, R>(
&mut self,
name: F,
read: R,
filename: G,
mime: Mime
) where
F: Display,
G: Into<String>,
R: 'a + AsyncRead + Send + Sync + Unpin,
pub fn add_async_reader_file_with_mime<F, G, R>(
&mut self,
name: F,
read: R,
filename: G,
mime: Mime
) where
F: Display,
G: Into<String>,
R: 'a + AsyncRead + Send + Sync + Unpin,
Adds a readable part to the Form as a file with a specified mime.
Examples
use common_multipart_rfc7578::client::multipart;
use futures_util::io::Cursor;
let bytes = Cursor::new("Hello World!");
let mut form = multipart::Form::default();
form.add_async_reader_file_with_mime("input", bytes, "filename.txt", mime::TEXT_PLAIN);
pub fn set_body<B>(self, req: Builder) -> Result<Request<B>, Error> where
B: From<Body<'a>>,
pub fn set_body<B>(self, req: Builder) -> Result<Request<B>, Error> where
B: From<Body<'a>>,
Updates a request instance with the multipart Content-Type header and the payload data.
Examples
use hyper::{Method, Request};
use hyper_multipart_rfc7578::client::multipart;
let mut req_builder = Request::post("http://localhost:80/upload");
let mut form = multipart::Form::default();
form.add_text("text", "Hello World!");
let req = form.set_body::<multipart::Body>(req_builder).unwrap();
pub fn set_body_convert<B, I>(self, req: Builder) -> Result<Request<B>, Error> where
I: From<Body<'a>> + Into<B>,
pub fn set_body_convert<B, I>(self, req: Builder) -> Result<Request<B>, Error> where
I: From<Body<'a>> + Into<B>,
Updates a request instance with the multipart Content-Type header and the payload data.
Allows converting body into an intermediate type.
Examples
use hyper::{Body, Method, Request};
use hyper_multipart_rfc7578::client::multipart;
let mut req_builder = Request::post("http://localhost:80/upload");
let mut form = multipart::Form::default();
form.add_text("text", "Hello World!");
let req = form.set_body_convert::<hyper::Body, multipart::Body>(req_builder).unwrap();
pub fn content_type(&self) -> String
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Form<'a>
impl<'a> Send for Form<'a>
impl<'a> Sync for Form<'a>
impl<'a> Unpin for Form<'a>
impl<'a> !UnwindSafe for Form<'a>
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> Instrument for T
impl<T> Instrument for T
sourcefn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
sourcefn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
fn vzip(self) -> V
sourceimpl<T> WithSubscriber for T
impl<T> WithSubscriber for T
sourcefn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> where
S: Into<Dispatch>,
Attaches the provided Subscriber
to this type, returning a
WithDispatch
wrapper. Read more
sourcefn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
Attaches the current default Subscriber
to this type, returning a
WithDispatch
wrapper. Read more