pub struct File<S: FileSubtype = GenericFile> { /* private fields */ }Expand description
A file parameter schema for file uploads and references.
File parameters support various file types through FileSubtype,
with MIME type filtering and size constraints.
This is the schema definition - it does not hold runtime values.
§Value Representation
File produces Value::Object with standard fields:
{
"id": "file-abc123",
"name": "document.pdf",
"size": 102400,
"mime": "application/pdf",
"url": "https://..."
}§Example
use paramdef::types::leaf::File;
use paramdef::subtype::{Image, Pdf};
// Generic file upload
let attachment = File::builder("attachment")
.label("Attachment")
.build();
// Image upload with size limit
let avatar = File::image("avatar")
.max_size_mb(5)
.required()
.build();
// PDF document
let document = File::pdf("contract")
.label("Contract PDF")
.required()
.build();Implementations§
Source§impl<S: FileSubtype> File<S>
impl<S: FileSubtype> File<S>
Sourcepub fn accept(&self) -> Vec<&str>
pub fn accept(&self) -> Vec<&str>
Returns the accepted MIME types.
Combines subtype’s accept list with any additional types.
Sourcepub fn max_size(&self) -> Option<u64>
pub fn max_size(&self) -> Option<u64>
Returns the maximum file size in bytes.
Returns the explicit max_size if set, otherwise the subtype’s default.
Sourcepub fn is_multiple(&self) -> bool
pub fn is_multiple(&self) -> bool
Returns whether multiple files are allowed.
Source§impl File<GenericFile>
impl File<GenericFile>
Sourcepub fn builder(key: impl Into<Key>) -> FileBuilder<GenericFile>
pub fn builder(key: impl Into<Key>) -> FileBuilder<GenericFile>
Creates a new builder for a generic file parameter.
Trait Implementations§
Source§impl<S: FileSubtype> Leaf for File<S>
impl<S: FileSubtype> Leaf for File<S>
Source§fn default_value(&self) -> Option<Value>
fn default_value(&self) -> Option<Value>
Returns the default value for this parameter, if set.
Source§impl<S: FileSubtype + 'static> Node for File<S>
impl<S: FileSubtype + 'static> Node for File<S>
Source§fn as_any_mut(&mut self) -> &mut dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Returns a mutable reference to the underlying type for downcasting.
Auto Trait Implementations§
impl<S> Freeze for File<S>where
S: Freeze,
impl<S> RefUnwindSafe for File<S>where
S: RefUnwindSafe,
impl<S> Send for File<S>
impl<S> Sync for File<S>
impl<S> Unpin for File<S>where
S: Unpin,
impl<S> UnwindSafe for File<S>where
S: UnwindSafe,
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