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