MCPcopy Create free account
hub / github.com/biblius/validify / parse_single_validation

Function parse_single_validation

validify_derive/src/validate/impl.rs:126–365  ·  view source on GitHub ↗
(
    meta: ParseNestedMeta<'_>,
    validators: &mut Vec<Validator>,
)

Source from the content-addressed store, hash-verified

124}
125
126fn parse_single_validation(
127 meta: ParseNestedMeta<'_>,
128 validators: &mut Vec<Validator>,
129) -> Result<(), syn::Error> {
130 if meta.path.is_ident(EMAIL) {
131 if meta.is_full_pattern() {
132 let validation = parse_email_full(&meta)?;
133 validators.push(Validator::Email(validation));
134 } else {
135 validators.push(Validator::Email(Email::default()));
136 }
137 return Ok(());
138 }
139
140 if meta.path.is_ident(URL) {
141 if meta.is_full_pattern() {
142 let validation = parse_url_full(&meta)?;
143 validators.push(Validator::Url(validation));
144 } else {
145 validators.push(Validator::Url(Url::default()));
146 }
147
148 return Ok(());
149 }
150
151 if meta.path.is_ident(LENGTH) {
152 let validation = parse_length(&meta)?;
153 validators.push(Validator::Length(validation));
154 return Ok(());
155 }
156
157 if meta.path.is_ident(RANGE) {
158 let validation = parse_range(&meta)?;
159 validators.push(Validator::Range(validation));
160 return Ok(());
161 }
162
163 if meta.path.is_ident(MUST_MATCH) {
164 if meta.is_single_path("must_match") {
165 let content;
166 parenthesized!(content in meta.input);
167 let Ok(id) = content.parse::<syn::Ident>() else {
168 return Err(meta.error("Invalid value given for `must_match` validation, must be a field on the current struct"));
169 };
170 validators.push(Validator::MustMatch(MustMatch::new(id)));
171 } else {
172 let validation = parse_must_match_full(&meta)?;
173 validators.push(Validator::MustMatch(validation));
174 }
175 return Ok(());
176 }
177
178 if meta.path.is_ident(CONTAINS) {
179 if meta.is_single_lit("contains") {
180 let content;
181 parenthesized!(content in meta.input);
182 let Ok(lit) = content.parse::<syn::Lit>() else {
183 return Err(meta.error(

Callers 1

collect_validationsFunction · 0.85

Calls 15

parse_lengthFunction · 0.85
parse_rangeFunction · 0.85
parse_must_match_fullFunction · 0.85
parse_contains_fullFunction · 0.85
parse_custom_fullFunction · 0.85
parse_regex_fullFunction · 0.85
PhoneClass · 0.85
RequiredClass · 0.85
InClass · 0.85
parse_in_fullFunction · 0.85
parse_ip_fullFunction · 0.85
parse_timeFunction · 0.85

Tested by

no test coverage detected