axum_extra::response::multiple

Struct Part

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

A single part of a multipart form as defined by https://www.w3.org/TR/html401/interact/forms.html#h-17.13.4 and RFC5758.

Implementations§

Source§

impl Part

Source

pub fn text(name: String, contents: &str) -> Self

Create a new part with Content-Type of text/plain with the supplied name and contents.

This form will not have a defined file name.

§Examples
use axum_extra::response::multiple::{MultipartForm, Part};

// create a form with a single part that has a field with a name of "foo",
// and a value of "abc"
let parts: Vec<Part> = vec![Part::text("foo".to_string(), "abc")];
let form = MultipartForm::from_iter(parts);
Source

pub fn file(field_name: &str, file_name: &str, contents: Vec<u8>) -> Self

Create a new part containing a generic file, with a Content-Type of application/octet-stream using the provided file name, field name, and contents.

If the MIME type of the file is known, consider using Part::raw_part.

§Examples
use axum_extra::response::multiple::{MultipartForm, Part};

// create a form with a single part that has a field with a name of "foo",
// with a file name of "foo.txt", and with the specified contents
let parts: Vec<Part> = vec![Part::file("foo", "foo.txt", vec![0x68, 0x68, 0x20, 0x6d, 0x6f, 0x6d])];
let form = MultipartForm::from_iter(parts);
Source

pub fn raw_part( name: &str, mime_type: &str, contents: Vec<u8>, filename: Option<&str>, ) -> Result<Self, &'static str>

Create a new part with more fine-grained control over the semantics of that part.

The caller is assumed to have set a valid MIME type.

This function will return an error if the provided MIME type is not valid.

§Examples
use axum_extra::response::multiple::{MultipartForm, Part};

// create a form with a single part that has a field with a name of "part_name",
// with a MIME type of "application/json", and the supplied contents.
let parts: Vec<Part> = vec![Part::raw_part("part_name", "application/json", vec![0x68, 0x68, 0x20, 0x6d, 0x6f, 0x6d], None).expect("MIME type must be valid")];
let form = MultipartForm::from_iter(parts);

Trait Implementations§

Source§

impl Debug for Part

Source§

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

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

impl FromIterator<Part> for MultipartForm

Source§

fn from_iter<T: IntoIterator<Item = Part>>(iter: T) -> Self

Creates a value from an iterator. Read more

Auto Trait Implementations§

§

impl Freeze for Part

§

impl RefUnwindSafe for Part

§

impl Send for Part

§

impl Sync for Part

§

impl Unpin for Part

§

impl UnwindSafe for Part

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