Skip to main content

FileData

Struct FileData 

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

An owned file: its bytes, and the file name and content type the client sent, when they are text. The output of MemorySink and a field type for typed extraction from buffered bodies.

The bytes are wiped on drop. Debug prints the length only.

§Examples

form_net::form! {
    pub struct Avatar {
        pub image: form_net::FileData,
    }
}
use form_net::FromForm;

let body = b"--X\r\nContent-Disposition: form-data; name=image; filename=\"me.png\"\r\nContent-Type: image/png\r\n\r\nPNG\r\n--X--";
let a = Avatar::from_multipart(b"multipart/form-data; boundary=X", body)?;
assert_eq!((a.image.bytes(), a.image.filename()), (&b"PNG"[..], Some("me.png")));

Implementations§

Source§

impl FileData

Source

pub fn bytes(&self) -> &[u8] ⓘ

The file’s bytes.

Source

pub fn into_bytes(self) -> Vec<u8> ⓘ

The file’s bytes, owned. They are no longer wiped by form-net.

Source

pub fn len(&self) -> usize

The length in bytes.

Source

pub fn is_empty(&self) -> bool

Whether the file is empty.

Source

pub fn filename(&self) -> Option<&str>

The client’s file name, as sent: never sanitized, never a path.

Source

pub fn content_type(&self) -> Option<&str>

The declared content type: a hint, never trusted.

Trait Implementations§

Source§

impl Debug for FileData

Source§

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

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

impl Default for FileData

Source§

fn default() -> Self

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

impl Drop for FileData

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl FromField for FileData

Source§

type Slot = Option<FileData>

What has arrived so far.
Source§

fn accept_file( slot: &mut Self::Slot, file: FileValue<'_>, ) -> Result<(), ValueError>

Takes one file. Read more
Source§

fn finish(slot: Self::Slot) -> Result<Self, ValueError>

The value, once every field has arrived. Read more
Source§

fn accept_text(slot: &mut Self::Slot, value: &str) -> Result<(), ValueError>

Takes one text value. 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> 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>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.