pub struct MemoryFileUpload { /* private fields */ }Expand description
MemoryFileUpload stores uploaded files in memory
Useful for small files or testing scenarios where disk I/O should be avoided.
Implementations§
Source§impl MemoryFileUpload
impl MemoryFileUpload
Sourcepub fn new(filename: String, content: Vec<u8>) -> Self
pub fn new(filename: String, content: Vec<u8>) -> Self
Create a new memory-based file upload
§Examples
use reinhardt_http::upload::MemoryFileUpload;
let upload = MemoryFileUpload::new(
"document.pdf".to_string(),
vec![0x25, 0x50, 0x44, 0x46]
);
assert_eq!(upload.filename(), "document.pdf");
assert_eq!(upload.size(), 4);Sourcepub fn with_content_type(
filename: String,
content: Vec<u8>,
content_type: String,
) -> Self
pub fn with_content_type( filename: String, content: Vec<u8>, content_type: String, ) -> Self
Create a memory upload with content type
§Examples
use reinhardt_http::upload::MemoryFileUpload;
let upload = MemoryFileUpload::with_content_type(
"image.png".to_string(),
vec![0x89, 0x50, 0x4E, 0x47],
"image/png".to_string()
);
assert_eq!(upload.content_type(), Some("image/png"));Sourcepub fn content_type(&self) -> Option<&str>
pub fn content_type(&self) -> Option<&str>
Get the content type
Sourcepub fn size(&self) -> usize
pub fn size(&self) -> usize
Get the file size in bytes
§Examples
use reinhardt_http::upload::MemoryFileUpload;
let upload = MemoryFileUpload::new("test.txt".to_string(), vec![1, 2, 3, 4, 5]);
assert_eq!(upload.size(), 5);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Check if the upload is empty
§Examples
use reinhardt_http::upload::MemoryFileUpload;
let empty = MemoryFileUpload::new("empty.txt".to_string(), vec![]);
assert!(empty.is_empty());
let non_empty = MemoryFileUpload::new("data.txt".to_string(), vec![1, 2, 3]);
assert!(!non_empty.is_empty());Sourcepub fn save_to_disk(&self, path: PathBuf) -> Result<(), FileUploadError>
pub fn save_to_disk(&self, path: PathBuf) -> Result<(), FileUploadError>
Save to disk
§Examples
use reinhardt_http::upload::MemoryFileUpload;
use std::path::PathBuf;
let upload = MemoryFileUpload::new("test.txt".to_string(), vec![1, 2, 3]);
let result = upload.save_to_disk(PathBuf::from("/tmp/test.txt"));
assert!(result.is_ok());Auto Trait Implementations§
impl Freeze for MemoryFileUpload
impl RefUnwindSafe for MemoryFileUpload
impl Send for MemoryFileUpload
impl Sync for MemoryFileUpload
impl Unpin for MemoryFileUpload
impl UnsafeUnpin for MemoryFileUpload
impl UnwindSafe for MemoryFileUpload
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more