Crates.io | xyz_validator |
lib.rs | xyz_validator |
version | 0.4.1 |
source | src |
created_at | 2022-11-22 06:13:20.367068 |
updated_at | 2022-11-25 21:33:37.238333 |
description | A set of validators. Currently, only Resource Query Language (RQL) validator is implemented. |
homepage | |
repository | https://github.com/spolanyev/xyz_validator |
max_upload_size | |
id | 720628 |
size | 33,052 |
Implemented:
Relational
exists(property)
Comparison
eq(property,value)
ne(property,value)
lt(property,value)
gt(property,value)
le(property,value)
ge(property,value)
Search
like(property,pattern)
List
in(property,(value1,...))
out(property,(value1,...))
Logical
use xyz_validator::{RqlValidator, ValidatorInterface};
fn main() {
let valid_rql_statement = "or(and(eq(name,John),eq(surname,Doe)),eq(surname,Smith))".to_owned();
let rql_validator: Box<dyn ValidatorInterface> = Box::new(RqlValidator::new(None));
assert!(rql_validator.is_valid(valid_rql_statement));
//to view errors we should define a callback function for `String` argument
fn your_handle_error_function(your_var: String) {
eprintln!("{}", your_var);
}
let rql_validator: Box<dyn ValidatorInterface> =
Box::new(RqlValidator::new(Some(your_handle_error_function)));
let invalid_rql_statement = "and(eq(name,John))".to_owned();
assert!(!rql_validator.is_valid(invalid_rql_statement));
//Operator `and` should have at least 2 nested queries
}