pub struct TemporaryFileUpload { /* private fields */ }Expand description
TemporaryFileUpload manages temporary uploaded files
Automatically cleans up temporary files when dropped.
Implementations§
Source§impl TemporaryFileUpload
impl TemporaryFileUpload
Sourcepub fn new(path: PathBuf) -> Self
pub fn new(path: PathBuf) -> Self
Create a new temporary file upload
§Examples
use reinhardt_http::upload::TemporaryFileUpload;
use std::path::PathBuf;
let temp = TemporaryFileUpload::new(PathBuf::from("/tmp/temp_file.dat"));
assert_eq!(temp.path().to_str().unwrap(), "/tmp/temp_file.dat");Sourcepub fn with_content(
path: PathBuf,
content: &[u8],
) -> Result<Self, FileUploadError>
pub fn with_content( path: PathBuf, content: &[u8], ) -> Result<Self, FileUploadError>
Create a temporary file with content
§Examples
use reinhardt_http::upload::TemporaryFileUpload;
use std::path::PathBuf;
let temp = TemporaryFileUpload::with_content(
PathBuf::from("/tmp/temp.txt"),
b"Hello, World!"
).unwrap();Sourcepub fn keep(&mut self)
pub fn keep(&mut self)
Disable automatic deletion
§Examples
use reinhardt_http::upload::TemporaryFileUpload;
use std::path::PathBuf;
let mut temp = TemporaryFileUpload::new(PathBuf::from("/tmp/keep_me.txt"));
temp.keep();
assert!(!temp.auto_delete());Sourcepub fn auto_delete(&self) -> bool
pub fn auto_delete(&self) -> bool
Check if auto-delete is enabled
Sourcepub fn read_content(&self) -> Result<Vec<u8>, FileUploadError>
pub fn read_content(&self) -> Result<Vec<u8>, FileUploadError>
Read file content
§Examples
use reinhardt_http::upload::TemporaryFileUpload;
use std::path::PathBuf;
let temp = TemporaryFileUpload::with_content(
PathBuf::from("/tmp/test.txt"),
b"content"
).unwrap();
let content = temp.read_content().unwrap();
assert_eq!(content, b"content");Trait Implementations§
Auto Trait Implementations§
impl Freeze for TemporaryFileUpload
impl RefUnwindSafe for TemporaryFileUpload
impl Send for TemporaryFileUpload
impl Sync for TemporaryFileUpload
impl Unpin for TemporaryFileUpload
impl UnsafeUnpin for TemporaryFileUpload
impl UnwindSafe for TemporaryFileUpload
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