pub struct Validator<R: Read> { /* private fields */ }Expand description
The JSON validator.
Implementations§
Source§impl<R: Read> Validator<R>
impl<R: Read> Validator<R>
Sourcepub fn new(read: R) -> Self
pub fn new(read: R) -> Self
Creates a new Validator instance with the given reader without any constraints.
You could prefer to use the from_slice, from_str, or from_reader functions
Sourcepub fn with_max_depth(self, max_depth: usize) -> Self
pub fn with_max_depth(self, max_depth: usize) -> Self
Sets the maximum depth of the JSON structure.
Sourcepub fn with_max_string_length(self, max_string_length: usize) -> Self
pub fn with_max_string_length(self, max_string_length: usize) -> Self
Sets the maximum length of strings.
Sourcepub fn with_max_array_entries(self, max_array_length: usize) -> Self
pub fn with_max_array_entries(self, max_array_length: usize) -> Self
Sets the maximum number of entries in arrays.
Sourcepub fn with_max_object_entries(self, max_object_length: usize) -> Self
pub fn with_max_object_entries(self, max_object_length: usize) -> Self
Sets the maximum number of entries in objects.
Sourcepub fn with_max_object_entry_name_length(
self,
max_object_entry_name_length: usize,
) -> Self
pub fn with_max_object_entry_name_length( self, max_object_entry_name_length: usize, ) -> Self
Sets the maximum length of object entry names.
Sourcepub fn allow_duplicate_object_entry_name(self) -> Self
pub fn allow_duplicate_object_entry_name(self) -> Self
Allows duplicate object entry names.
Sourcepub fn disallow_duplicate_object_entry_name(self) -> Self
pub fn disallow_duplicate_object_entry_name(self) -> Self
Disallows duplicate object entry names.
Sourcepub fn validate(self) -> Result<(), ValidatorError>
pub fn validate(self) -> Result<(), ValidatorError>
Validates the JSON payload in a single call, and consumes current Validator instance.
§Returns
Ok(())- If the JSON payload is valid and did not violate any constraints.Err- If the JSON payload is invalid or violates any constraints.
§Errors
Error- If the JSON payload is invalid or violates any constraints.
In the extreme case, the error might return an Err and indicate
this crate is running into buggy code.
Please report it to the crate maintainer if you see this error.
Sourcepub fn validate_with_steps(
&mut self,
steps: usize,
) -> Result<bool, ValidatorError>
pub fn validate_with_steps( &mut self, steps: usize, ) -> Result<bool, ValidatorError>
Validates the JSON payload in multiple calls.
§Arguments
steps- The number of steps to validate the JSON payload, roughly corresponds to the number of tokens processed.
§Returns
Ok(true)- If the validation is finished and no errors.Ok(false)- If the validation is not finished yet, and you should call this function again.Err- If the JSON payload is invalid or violates any constraints.
§Errors
Error- If the JSON payload is invalid or violates any constraints.
In the extreme case, the error might return an Err and indicate
this crate is running into buggy code.
Please report it to the crate maintainer if you see this error.
§WARNING
The validator will be invalidated once this method
returns an Err or Ok(true),
and calling any methods for Validator instance is undefined behavior.