| 1 |
use quote::quote; |
| 2 |
|
| 3 |
use crate::types::DoesNotContain; |
| 4 |
use crate::utils::{quote_code, quote_message, CrateName}; |
| 5 |
|
| 6 |
pub fn does_not_contain_tokens( |
| 7 |
crate_name: &CrateName, |
| 8 |
does_not_contain: DoesNotContain, |
| 9 |
field_name: &proc_macro2::TokenStream, |
| 10 |
field_name_str: &str, |
| 11 |
) -> proc_macro2::TokenStream { |
| 12 |
let p = does_not_contain.pattern; |
| 13 |
|
| 14 |
let (needle, needle_err) = |
| 15 |
(quote!(#p), quote!(err.add_param(::std::borrow::Cow::from("needle"), &#p);)); |
| 16 |
|
| 17 |
let message = quote_message(does_not_contain.message); |
| 18 |
let code = quote_code(crate_name, does_not_contain.code, "does_not_contain"); |
| 19 |
|
| 20 |
quote! { |
| 21 |
if !#field_name.validate_does_not_contain(#needle) { |
| 22 |
#code |
| 23 |
#message |
| 24 |
#needle_err |
| 25 |
err.add_param(::std::borrow::Cow::from("value"), &#field_name); |
| 26 |
errors.add(#field_name_str, err); |
| 27 |
} |
| 28 |
} |
| 29 |
} |