#query-language #validation #resources #xyz #implemented #rql #validator-interface

bin+lib xyz_validator

A set of validators. Currently, only Resource Query Language (RQL) validator is implemented.

8 unstable releases (3 breaking)

0.4.1 Nov 25, 2022
0.4.0 Nov 25, 2022
0.3.0 Nov 25, 2022
0.2.2 Nov 25, 2022
0.1.1 Nov 23, 2022

#8 in #xyz

29 downloads per month

MIT/Apache

20KB
375 lines

Examples

Basic usage:

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
}

No runtime deps