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: TThe constructed struct (invalid fields use Default).
Implementations§
Source§impl<T> ParseResult<T>
impl<T> ParseResult<T>
Sourcepub fn new(value: T, field_results: Vec<FieldResult>) -> ParseResult<T>
pub fn new(value: T, field_results: Vec<FieldResult>) -> ParseResult<T>
Create a new parse result.
Sourcepub fn fields(&self) -> &[FieldResult]
pub fn fields(&self) -> &[FieldResult]
All per-field results.
Sourcepub fn field(&self, name: &str) -> Option<&FieldResult>
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.
Sourcepub fn valid_fields(&self) -> Vec<&FieldResult>
pub fn valid_fields(&self) -> Vec<&FieldResult>
Only the fields that passed validation.
Sourcepub fn error_fields(&self) -> Vec<&FieldResult>
pub fn error_fields(&self) -> Vec<&FieldResult>
Only the fields that failed validation.
Sourcepub fn has_errors(&self) -> bool
pub fn has_errors(&self) -> bool
Whether at least one field failed.
Sourcepub fn valid_count(&self) -> usize
pub fn valid_count(&self) -> usize
Number of valid fields.
Sourcepub fn error_count(&self) -> usize
pub fn error_count(&self) -> usize
Number of invalid fields.
Sourcepub fn into_value(self) -> T
pub fn into_value(self) -> T
Consume and return the inner struct.
Sourcepub fn into_parts(self) -> (T, Vec<FieldResult>)
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,
impl<T> ParseResult<T>where
T: Serialize,
Sourcepub fn save_to_file(&self, path: &Path) -> Result<(), Error>
pub fn save_to_file(&self, path: &Path) -> Result<(), Error>
Serialize the struct to a JSON file.
Requires the serialize and std features.
Sourcepub fn to_json_string(&self) -> Result<String, Error>
pub fn to_json_string(&self) -> Result<String, Error>
Serialize the struct to a JSON string.
Requires the serialize feature.
Sourcepub fn to_json_value(&self) -> Result<Value, Error>
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,
impl<T> Debug for ParseResult<T>where
T: Debug,
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> 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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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