(input: syn::parse::ParseStream)
| 176 | |
| 177 | impl Parse for StaticListArgs { |
| 178 | fn parse(input: syn::parse::ParseStream) -> syn::Result<Self> { |
| 179 | let mut ty: Option<LitStr> = None; |
| 180 | let mut name: Option<LitStr> = None; |
| 181 | let mut expected_count: Option<LitInt> = None; |
| 182 | |
| 183 | while !input.is_empty() { |
| 184 | let lookahead = input.lookahead1(); |
| 185 | if lookahead.peek(keywords::ty) { |
| 186 | let res = input.parse::<KeyValueArg<keywords::ty, LitStr>>()?; |
| 187 | ty = Some(res.val); |
| 188 | } else if lookahead.peek(keywords::name) { |
| 189 | let res = input.parse::<KeyValueArg<keywords::name, LitStr>>()?; |
| 190 | name = Some(res.val); |
| 191 | } else if lookahead.peek(keywords::expected_count) { |
| 192 | let res = input.parse::<KeyValueArg<keywords::expected_count, LitInt>>()?; |
| 193 | expected_count = Some(res.val); |
| 194 | } else if lookahead.peek(Token![,]) { |
| 195 | let _ = input.parse::<Token![,]>()?; |
| 196 | } else { |
| 197 | return Err(input.error("Unexpected argument")); |
| 198 | } |
| 199 | } |
| 200 | |
| 201 | let mut missing_args = Vec::new(); |
| 202 | if ty.is_none() { |
| 203 | missing_args.push("ty"); |
| 204 | } |
| 205 | if name.is_none() { |
| 206 | missing_args.push("name"); |
| 207 | } |
| 208 | if expected_count.is_none() { |
| 209 | missing_args.push("expected_count"); |
| 210 | } |
| 211 | |
| 212 | if !missing_args.is_empty() { |
| 213 | input.error(format!("Missing arguments {:?}", missing_args)); |
| 214 | } |
| 215 | |
| 216 | Ok(StaticListArgs { |
| 217 | ty: ty.expect("checked above"), |
| 218 | name: name.expect("checked above"), |
| 219 | expected_count: expected_count.expect("checked above"), |
| 220 | }) |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | fn type_matches(static_ty: &Type, expected_ty: &LitStr) -> bool { |
no test coverage detected