Skip to main content

Form

Struct Form 

Source
pub struct Form { /* private fields */ }
Available on crate feature multipart only.
Expand description

A multipart form body.

Generates a random boundary on construction. Add named Parts with text, bytes, file, or part, then convert to a Body (or feed via RequestBuilder::multipart).

Implementations§

Source§

impl Form

Source

pub fn new() -> Self

Create a new empty Form with a random boundary.

Source

pub fn boundary(&self) -> &str

The boundary string used to separate this form’s parts.

Source

pub fn content_type(&self) -> HeaderValue

The Content-Type header value (multipart/form-data; boundary=…).

Source

pub fn text<N, V>(self, name: N, value: V) -> Self
where N: Into<Cow<'static, str>>, V: Into<Cow<'static, str>>,

Add a text part to the form.

Source

pub fn bytes<N, B>(self, name: N, value: B) -> Self
where N: Into<Cow<'static, str>>, B: Into<Bytes>,

Add a bytes part to the form.

Source

pub async fn file<N, P>(self, name: N, path: P) -> Result<Self>
where N: Into<Cow<'static, str>>, P: AsRef<Path>,

Add a file part to the form. Reads the file asynchronously, infers the MIME type from the file extension (falling back to application/octet-stream), and sets filename from the path.

Source

pub async fn with_field_spec(self, spec: &str) -> Result<Self, FieldSpecError>

Add a part described by a compact name=value field-spec string.

See FieldSpec for the supported syntax (the same convention used by curl -F, httpie, and similar tools). Performs the I/O implied by =@ (file), =< (file-as-text), and =@- / =<- (stdin) sources; the =value form is purely textual.

Source

pub fn part<N>(self, name: N, part: Part) -> Self
where N: Into<Cow<'static, str>>,

Add a custom Part to the form.

Source

pub fn content_length(&self) -> Option<u64>

Total content length of the encoded form, if every part has a known size. Returns None otherwise (use chunked transfer encoding in that case).

Computed analytically — no headers are rendered into a buffer.

Source

pub fn into_stream(self) -> impl Stream<Item = Result<Bytes, BoxError>> + Send

Convert this form into a stream of body chunks.

Per-part overhead: one heap-allocated framing chunk (boundary delimiter + headers, prefixed with CRLF on all but the first part) and the part body. Bytes-bodied parts are emitted in a single chunk; streamed bodies pass through their underlying chunks unchanged.

Source

pub fn into_body(self) -> Body

Consume the form and produce a Body ready to be set on a request. Use content_type and content_length to set the relevant request headers.

Trait Implementations§

Source§

impl Debug for Form

Source§

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

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

impl Default for Form

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !Freeze for Form

§

impl !RefUnwindSafe for Form

§

impl !Sync for Form

§

impl !UnwindSafe for Form

§

impl Send for Form

§

impl Unpin for Form

§

impl UnsafeUnpin for Form

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<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> RamaFrom<T> for U
where U: From<T>,

Source§

fn rama_from(value: T) -> U

Source§

impl<T, U, CrateMarker> RamaInto<U, CrateMarker> for T
where U: RamaFrom<T, CrateMarker>,

Source§

fn rama_into(self) -> U

Source§

impl<T, U> RamaTryFrom<T> for U
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

Source§

fn rama_try_from(value: T) -> Result<U, <U as RamaTryFrom<T>>::Error>

Source§

impl<T, U, CrateMarker> RamaTryInto<U, CrateMarker> for T
where U: RamaTryFrom<T, CrateMarker>,

Source§

type Error = <U as RamaTryFrom<T, CrateMarker>>::Error

Source§

fn rama_try_into(self) -> Result<U, <U as RamaTryFrom<T, CrateMarker>>::Error>

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more