pub struct Part { /* private fields */ }Expand description
A single part in a multipart form.
Each part can be text, binary data, or a file with optional filename and content type.
Implementations§
Source§impl Part
impl Part
Sourcepub fn new(name: impl Into<String>, data: impl Into<Bytes>) -> Self
pub fn new(name: impl Into<String>, data: impl Into<Bytes>) -> Self
Create a new part with the given name and data.
Sourcepub fn text(name: impl Into<String>, value: impl Into<String>) -> Self
pub fn text(name: impl Into<String>, value: impl Into<String>) -> Self
Create a text part.
Sets the content type to text/plain; charset=utf-8.
Sourcepub fn bytes(name: impl Into<String>, data: impl Into<Bytes>) -> Self
pub fn bytes(name: impl Into<String>, data: impl Into<Bytes>) -> Self
Create a binary part.
Sets the content type to application/octet-stream.
Sourcepub fn file(
name: impl Into<String>,
filename: impl Into<String>,
data: impl Into<Bytes>,
) -> Self
pub fn file( name: impl Into<String>, filename: impl Into<String>, data: impl Into<Bytes>, ) -> Self
Create a file part with filename.
The content type is guessed from the filename extension, or defaults
to application/octet-stream if unknown.
Sourcepub fn with_filename(self, filename: impl Into<String>) -> Self
pub fn with_filename(self, filename: impl Into<String>) -> Self
Set the filename for this part.
Sourcepub fn with_content_type(self, content_type: impl Into<String>) -> Self
pub fn with_content_type(self, content_type: impl Into<String>) -> Self
Set the content type for this part.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get the content type, if set.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more