Struct Multipart

Source
pub struct Multipart<'n, 'd> { /* private fields */ }
Expand description

A multipart request which writes all fields at once upon being provided an output stream.

Sacrifices static dispatch for support for dynamic construction. Reusable.

§Lifetimes
  • 'n: Lifetime for field names; will only escape this struct in LazyIoError<'n>.
  • 'd: Lifetime for data: will only escape this struct in PreparedFields<'d>.

Implementations§

Source§

impl<'n, 'd> Multipart<'n, 'd>

Source

pub fn client_request<U: IntoUrl>( &mut self, client: &Client, url: U, ) -> HyperResult<Response>

§Feature: hyper

Complete a POST request with the given hyper::client::Client and URL.

Supplies the fields in the body, optionally setting the content-length header if applicable (all added fields were text or files, i.e. no streams).

Source

pub fn client_request_mut<U: IntoUrl, F: FnOnce(RequestBuilder<'_>) -> RequestBuilder<'_>>( &mut self, client: &Client, url: U, mut_fn: F, ) -> HyperResult<Response>

§Feature: hyper

Complete a POST request with the given hyper::client::Client and URL; allows mutating the hyper::client::RequestBuilder via the passed closure.

Note that the body, and the ContentType and ContentLength headers will be overwritten, either by this method or by Hyper.

Source§

impl<'n, 'd> Multipart<'n, 'd>

Source

pub fn new() -> Self

Initialize a new lazy dynamic request.

Source

pub fn add_text<N, T>(&mut self, name: N, text: T) -> &mut Self
where N: Into<Cow<'n, str>>, T: Into<Cow<'d, str>>,

Add a text field to this request.

Source

pub fn add_file<N, P>(&mut self, name: N, path: P) -> &mut Self
where N: Into<Cow<'n, str>>, P: IntoCowPath<'d>,

Add a file field to this request.

§Note

Does not check if path exists.

Source

pub fn add_stream<N, R, F>( &mut self, name: N, stream: R, filename: Option<F>, mime: Option<Mime>, ) -> &mut Self
where N: Into<Cow<'n, str>>, R: Read + 'd, F: Into<Cow<'n, str>>,

Add a generic stream field to this request,

Source

pub fn send<R: HttpRequest>( &mut self, req: R, ) -> Result<<R::Stream as HttpStream>::Response, LazyError<'n, <R::Stream as HttpStream>::Error>>

Convert req to HttpStream, write out the fields in this request, and finish the request, returning the response if successful, or the first error encountered.

If any files were added by path they will now be opened for reading.

Source

pub fn prepare(&mut self) -> LazyIoResult<'n, PreparedFields<'d>>

Export the multipart data contained in this lazy request as an adaptor which implements Read.

During this step, if any files were added by path then they will be opened for reading and their length measured.

Trait Implementations§

Source§

impl<'n, 'd> Debug for Multipart<'n, 'd>

Source§

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

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

impl<'n, 'd> Default for Multipart<'n, 'd>

Source§

fn default() -> Multipart<'n, 'd>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<'n, 'd> Freeze for Multipart<'n, 'd>

§

impl<'n, 'd> !RefUnwindSafe for Multipart<'n, 'd>

§

impl<'n, 'd> !Send for Multipart<'n, 'd>

§

impl<'n, 'd> !Sync for Multipart<'n, 'd>

§

impl<'n, 'd> Unpin for Multipart<'n, 'd>

§

impl<'n, 'd> !UnwindSafe for Multipart<'n, 'd>

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.
Source§

impl<T> Typeable for T
where T: Any,

Source§

fn get_type(&self) -> TypeId

Get the TypeId of this object.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> DebugAny for T
where T: Any + Debug,

Source§

impl<T> UnsafeAny for T
where T: Any,