Skip to main content

ParseResult

Struct ParseResult 

Source
pub struct ParseResult<T> {
    pub value: T,
    /* private fields */
}
Expand description

Result of lenient parsing: contains the (possibly partial) struct and per-field diagnostics.

Created by parse_lenient() / parse_lenient_value() generated by impl_validate_fields!.

The struct is always constructed — invalid fields fall back to Default::default(). You can inspect which fields passed/failed via fields(), and save the result to a file at any time via save_to_file() (requires the serialize feature).

Fields§

§value: T

The constructed struct (invalid fields use Default).

Implementations§

Source§

impl<T> ParseResult<T>

Source

pub fn new(value: T, field_results: Vec<FieldResult>) -> Self

Create a new parse result.

Source

pub fn fields(&self) -> &[FieldResult]

All per-field results.

Source

pub fn field(&self, name: &str) -> Option<&FieldResult>

Get a specific field’s result by name.

Returns None if no field with that name exists.

Source

pub fn valid_fields(&self) -> Vec<&FieldResult>

Only the fields that passed validation.

Source

pub fn error_fields(&self) -> Vec<&FieldResult>

Only the fields that failed validation.

Source

pub fn is_valid(&self) -> bool

Whether all fields passed validation.

Source

pub fn has_errors(&self) -> bool

Whether at least one field failed.

Source

pub fn valid_count(&self) -> usize

Number of valid fields.

Source

pub fn error_count(&self) -> usize

Number of invalid fields.

Source

pub fn into_value(self) -> T

Consume and return the inner struct.

Source

pub fn into_parts(self) -> (T, Vec<FieldResult>)

Consume and return both the struct and field results.

Trait Implementations§

Source§

impl<T: Debug> Debug for ParseResult<T>

Source§

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

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

impl<T: Debug> Display for ParseResult<T>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for ParseResult<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ParseResult<T>
where T: RefUnwindSafe,

§

impl<T> Send for ParseResult<T>
where T: Send,

§

impl<T> Sync for ParseResult<T>
where T: Sync,

§

impl<T> Unpin for ParseResult<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for ParseResult<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for ParseResult<T>
where T: 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> 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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. 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.