Struct curl::easy::Part

source ·
pub struct Part<'form, 'data> { /* private fields */ }
Expand description

One part in a multipart upload, added to a Form.

Implementations§

source§

impl<'form, 'data> Part<'form, 'data>

source

pub fn contents(&mut self, contents: &'data [u8]) -> &mut Self

A pointer to the contents of this part, the actual data to send away.

source

pub fn file_content<P>(&mut self, file: P) -> &mut Self
where P: AsRef<Path>,

Causes this file to be read and its contents used as data in this part

This part does not automatically become a file upload part simply because its data was read from a file.

§Errors

If the filename has any internal nul bytes or if on Windows it does not contain a unicode filename then the add function will eventually return an error.

source

pub fn file<P>(&mut self, file: &'data P) -> &mut Self
where P: AsRef<Path> + ?Sized,

Makes this part a file upload part of the given file.

Sets the filename field to the basename of the provided file name, and it reads the contents of the file and passes them as data and sets the content type if the given file matches one of the internally known file extensions.

The given upload file must exist entirely on the filesystem before the upload is started because libcurl needs to read the size of it beforehand.

Multiple files can be uploaded by calling this method multiple times and content types can also be configured for each file (by calling that next).

§Errors

If the filename has any internal nul bytes or if on Windows it does not contain a unicode filename then this function will cause add to return an error when called.

source

pub fn content_type(&mut self, content_type: &'data str) -> &mut Self

Used in combination with Part::file, provides the content-type for this part, possibly instead of choosing an internal one.

§Panics

This function will panic if content_type contains an internal nul byte.

source

pub fn filename<P>(&mut self, name: &'data P) -> &mut Self
where P: AsRef<Path> + ?Sized,

Used in combination with Part::file, provides the filename for this part instead of the actual one.

§Errors

If name contains an internal nul byte, or if on Windows the path is not valid unicode then this function will return an error when add is called.

source

pub fn buffer<P>(&mut self, name: &'data P, data: Vec<u8>) -> &mut Self
where P: AsRef<Path> + ?Sized,

This is used to provide a custom file upload part without using the file method above.

The first parameter is for the filename field and the second is the in-memory contents.

§Errors

If name contains an internal nul byte, or if on Windows the path is not valid unicode then this function will return an error when add is called.

source

pub fn content_header(&mut self, headers: List) -> &mut Self

Specifies extra headers for the form POST section.

Appends the list of headers to those libcurl automatically generates.

source

pub fn add(&mut self) -> Result<(), FormError>

Attempts to add this part to the Form that it was created from.

If any error happens while adding, that error is returned, otherwise Ok(()) is returned.

Trait Implementations§

source§

impl<'form, 'data> Debug for Part<'form, 'data>

source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'form, 'data> RefUnwindSafe for Part<'form, 'data>

§

impl<'form, 'data> !Send for Part<'form, 'data>

§

impl<'form, 'data> !Sync for Part<'form, 'data>

§

impl<'form, 'data> Unpin for Part<'form, 'data>

§

impl<'form, 'data> !UnwindSafe for Part<'form, 'data>

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

§

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

§

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.