(variant: &Variant, post_parse_steps: &TokenStream)
| 325 | |
| 326 | impl VariantPlan { |
| 327 | fn new(variant: &Variant, post_parse_steps: &TokenStream) -> Result<Self> { |
| 328 | let ident = variant.ident.clone(); |
| 329 | let parse_mode = ParseArg::from_attributes(&variant.attrs)?.parse_mode(); |
| 330 | let variant_atom = extract_atom(&variant.attrs)?; |
| 331 | let fields = Field::from_fields(&variant.fields)?; |
| 332 | let first_type = fields |
| 333 | .first() |
| 334 | .map(|f| f.ty.clone()) |
| 335 | .ok_or_else(|| Error::new(ident.span(), "enum variant must have at least one field"))?; |
| 336 | let members = members_tokens(&variant.fields); |
| 337 | |
| 338 | // Prefer variant-level atom; fall back to first field's atom except for |
| 339 | // must-occur variants with all-optional fields. |
| 340 | let all_optional = fields.iter().all(|f| f.ty.is_option()); |
| 341 | let effective_atom = if variant_atom.is_some() { |
| 342 | variant_atom |
| 343 | } else if (parse_mode == FieldParseMode::OneMustOccur || parse_mode == FieldParseMode::AllMustOccur) |
| 344 | && all_optional |
| 345 | { |
| 346 | None |
| 347 | } else { |
| 348 | fields.first().and_then(|f| f.atom.clone()) |
| 349 | }; |
| 350 | |
| 351 | Ok(Self { |
| 352 | ident, |
| 353 | first_type, |
| 354 | effective_atom, |
| 355 | parse_mode, |
| 356 | fields, |
| 357 | members, |
| 358 | post_parse_steps: post_parse_steps.clone(), |
| 359 | }) |
| 360 | } |
| 361 | |
| 362 | /// Render the body for this variant, consuming where-bounds into `wc`. |
| 363 | /// Picks `SequentialPlan` or `MustOccurPlan` based on `parse_mode`. |
nothing calls this directly
no test coverage detected