Skip to main content

Binder

Struct Binder 

Source
pub struct Binder { /* private fields */ }
Expand description

Accumulates field-level binding failures into one 400 response.

Binding is best-effort: a bad field records an error and yields None, the remaining fields still bind, and the request is rejected once at the end with every failure listed — matching ASP.NET Core’s ModelState.

Implementations§

Source§

impl Binder

Source

pub fn new() -> Self

A binder with no recorded errors.

Source

pub fn has_errors(&self) -> bool

Whether any field failed.

Source

pub fn errors(&self) -> &[FieldError]

The recorded failures, in binding order.

Source

pub fn into_error(self) -> Error

Consume the binder, yielding the 400 ProblemDetails error.

The response body carries errors as { "field": ["message"] }.

Source

pub fn missing(&mut self, field: &str)

Record the canonical “required” failure for field.

Source

pub fn invalid(&mut self, field: &str, kind: &str, value: &str)

Record an unparsable value for field.

Source

pub fn unknown_field(&mut self, name: &str)

Record a JSON key that no field claimed (deny_unknown_fields).

Source

pub fn required<T: FromStr>( &mut self, raw: Option<&str>, field: &str, kind: &str, ) -> Option<T>

Parse a required scalar.

Returns None (and records an error) when the value is absent or unparsable; the caller checks Binder::has_errors before building the request.

Source

pub fn optional<T: FromStr>( &mut self, raw: Option<&str>, field: &str, kind: &str, ) -> Option<T>

Parse an optional scalar: absent is None, present-but-invalid is an error (never silently None).

Source

pub fn list<T: FromStr>( &mut self, raw: &[&str], field: &str, kind: &str, ) -> Vec<T>

Parse every occurrence of a repeated value into a list.

An empty list is valid (ASP.NET Core binds missing collections as empty); unparsable elements are errors.

Source

pub fn take<T>(&mut self, value: Option<T>, field: &str) -> Option<T>

Record a “required” failure for an already-extracted optional value.

Used for body fields: serde has already validated the body, so a missing value here means the field was skipped by the shadow struct.

Source

pub fn required_file( &mut self, file: Option<&FormFile>, field: &str, ) -> Option<FormFile>

The first uploaded file, required.

Source

pub fn optional_file(&mut self, file: Option<&FormFile>) -> Option<FormFile>

The first uploaded file, optional.

Source

pub fn files(&mut self, files: Vec<&FormFile>) -> Vec<FormFile>

Every uploaded file under name.

Trait Implementations§

Source§

impl Default for Binder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more