Skip to main content

MultipartBuilder

Struct MultipartBuilder 

Source
pub struct MultipartBuilder { /* private fields */ }
Expand description

Builder for multipart/form-data bodies per RFC 7578.

§Example

use oxihttp_core::multipart::MultipartBuilder;

let builder = MultipartBuilder::new()
    .add_text("username", "alice")
    .add_file("avatar", "pic.png", "image/png", b"PNG\r\n".as_ref());

let content_type = builder.content_type();
let body_bytes = builder.build();

Implementations§

Source§

impl MultipartBuilder

Source

pub fn new() -> Self

Create a new builder with an auto-generated boundary.

Source

pub fn boundary(&self) -> &str

Return the boundary string (without leading --).

Source

pub fn content_type(&self) -> String

Return the full Content-Type header value including the boundary parameter.

Set this as the Content-Type header when sending the body.

Source

pub fn add_text(self, name: &str, value: impl Into<String>) -> Self

Add a text field part.

Source

pub fn add_file( self, name: &str, filename: &str, content_type: &str, body: impl Into<Bytes>, ) -> Self

Add a file/binary part.

Source

pub fn add_part(self, part: Part) -> Self

Add a pre-constructed Part.

Source

pub fn build(self) -> Bytes

Serialise to a Bytes buffer containing the complete multipart wire format.

Automatically handles boundary collision: if the boundary string occurs literally inside any part body, a numeric suffix is appended and the check repeats until the boundary is guaranteed unique across all part bodies.

Note: the uniqueness check searches for the bare boundary string (conservative — no false negatives). The actual wire delimiter is --<boundary>, but matching the bare string is safe because any occurrence of the bare string would also produce a collision in the delimiter form.

Trait Implementations§

Source§

impl Clone for MultipartBuilder

Source§

fn clone(&self) -> MultipartBuilder

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MultipartBuilder

Source§

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

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

impl Default for MultipartBuilder

Source§

fn default() -> Self

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

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.