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
impl FileData
Sourcepub fn into_bytes(self) -> Vec<u8> ⓘ
pub fn into_bytes(self) -> Vec<u8> ⓘ
The file’s bytes, owned. They are no longer wiped by form-net.
Sourcepub fn filename(&self) -> Option<&str>
pub fn filename(&self) -> Option<&str>
The client’s file name, as sent: never sanitized, never a path.
Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
The declared content type: a hint, never trusted.
Trait Implementations§
Source§impl FromField for FileData
impl FromField for FileData
Source§fn accept_file(
slot: &mut Self::Slot,
file: FileValue<'_>,
) -> Result<(), ValueError>
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>
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>
fn accept_text(slot: &mut Self::Slot, value: &str) -> Result<(), ValueError>
Takes one text value. Read more
Auto Trait Implementations§
impl Freeze for FileData
impl RefUnwindSafe for FileData
impl Send for FileData
impl Sync for FileData
impl Unpin for FileData
impl UnsafeUnpin for FileData
impl UnwindSafe for FileData
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