greyblake / nutype

Rust newtype with guarantees 🇺🇦 🦀

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Rename validator `with =` to `predicate = `

greyblake opened this issue · comments

Context

Currently it's possible to use for validation a custom function that returns either true or false. This function or closure is specified with with = attribute.
In this issue we want it to rename to predicate =

Motivation

  1. It's natural to call predicate things that return bool
  2. It will enable us to introduce custom with = function, which instead of bool will return any variant of error, so users may have more control the validation logic.

Specs

  • Rename validation rule for all type families (integer, float, string) from with to predicate
  • Do not rename with = sanitizer
  • Adjust the tests correspondingly (to run all suite make test)
  • Handle with = validation attribute by returning an error, saying that it's renamed into predicate = . Add an ui test for this.
  • Add a note about breaking change in CHANGELOG.md

Acceptance Criteria

  1. The following compiles
#[nutype(validate(predicate = |x| x % 2 == 0))]
pub struct Even(u32);
  1. The following fails ,saying that with = was renamed to predicate =
#[nutype(validate(with = |x| x % 2 == 0))]
pub struct Even(u32);

Addressed in #76