File

Struct File 

Source
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>

Source

pub fn subtype(&self) -> &S

Returns the file subtype.

Source

pub fn accept(&self) -> Vec<&str>

Returns the accepted MIME types.

Combines subtype’s accept list with any additional types.

Source

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.

Source

pub fn is_multiple(&self) -> bool

Returns whether multiple files are allowed.

Source

pub fn flags(&self) -> Flags

Returns the flags.

Source§

impl File<GenericFile>

Source

pub fn builder(key: impl Into<Key>) -> FileBuilder<GenericFile>

Creates a new builder for a generic file parameter.

Source§

impl File<Image>

Source

pub fn image(key: impl Into<Key>) -> FileBuilder<Image>

Creates an image file parameter builder.

Source§

impl File<Photo>

Source

pub fn photo(key: impl Into<Key>) -> FileBuilder<Photo>

Creates a photo file parameter builder.

Source§

impl File<Avatar>

Source

pub fn avatar(key: impl Into<Key>) -> FileBuilder<Avatar>

Creates an avatar file parameter builder.

Source§

impl File<Pdf>

Source

pub fn pdf(key: impl Into<Key>) -> FileBuilder<Pdf>

Creates a PDF file parameter builder.

Source§

impl File<Document>

Source

pub fn document(key: impl Into<Key>) -> FileBuilder<Document>

Creates a document file parameter builder.

Source§

impl File<Video>

Source

pub fn video(key: impl Into<Key>) -> FileBuilder<Video>

Creates a video file parameter builder.

Source§

impl File<Audio>

Source

pub fn audio(key: impl Into<Key>) -> FileBuilder<Audio>

Creates an audio file parameter builder.

Source§

impl File<Archive>

Source

pub fn archive(key: impl Into<Key>) -> FileBuilder<Archive>

Creates an archive file parameter builder.

Source§

impl File<Signature>

Source

pub fn signature(key: impl Into<Key>) -> FileBuilder<Signature>

Creates a signature file parameter builder.

Trait Implementations§

Source§

impl<S: Clone + FileSubtype> Clone for File<S>

Source§

fn clone(&self) -> File<S>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<S: Debug + FileSubtype> Debug for File<S>

Source§

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

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

impl<S: FileSubtype> Leaf for File<S>

Source§

fn default_value(&self) -> Option<Value>

Returns the default value for this parameter, if set.
Source§

impl<S: FileSubtype + 'static> Node for File<S>

Source§

fn metadata(&self) -> &Metadata

Returns the node’s metadata.
Source§

fn key(&self) -> &Key

Returns the node’s unique key.
Source§

fn kind(&self) -> NodeKind

Returns the node’s kind (category).
Source§

fn as_any(&self) -> &dyn Any

Returns a reference to the underlying type for downcasting.
Source§

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> 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.