greyblake / nutype

Rust newtype with guarantees πŸ‡ΊπŸ‡¦ πŸ¦€
MIT License
1.4k stars 23 forks source link

Wrong error message when regex feature is not enabled #172

Closed greyblake closed 1 month ago

greyblake commented 1 month ago

Having the following code:

use nutype::nutype;

#[nutype(validate(regex = "^[0-9]{3}-[0-9]{3}$"))]
pub struct PhoneNumber(String);

fn main() {}

without regex feature not enabled, the following error is spit out:

error: Unknown validation attribute: `regex`.
       Possible attributes are `len_char_min`, `len_char_max`, `not_empty`, `predicate`, `regex`, `with`, `error`.
 --> dummy/src/main.rs:3:19
  |
3 | #[nutype(validate(regex = "^[0-9]{3}-[0-9]{3}$"))]
  |                   ^^^^^

The error is confusing. Instead it should say that regex feature has to be enabled.