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>) -> ParseResult<T>

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.

Source§

impl<T> ParseResult<T>
where T: Serialize,

Source

pub fn save_to_file(&self, path: &Path) -> Result<(), Error>

Serialize the struct to a JSON file.

Requires the serialize and std features.

Source

pub fn to_json_string(&self) -> Result<String, Error>

Serialize the struct to a JSON string.

Requires the serialize feature.

Source

pub fn to_json_value(&self) -> Result<Value, Error>

Serialize the struct to a serde_json::Value.

Requires the serialize feature.

Trait Implementations§

Source§

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

Source§

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

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

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

Source§

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

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

Source§

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

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
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