MCPcopy Create free account
hub / github.com/csskit/csskit / new

Method new

crates/csskit_derives/src/parse.rs:327–360  ·  view source on GitHub ↗
(variant: &Variant, post_parse_steps: &TokenStream)

Source from the content-addressed store, hash-verified

325
326impl 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`.

Callers

nothing calls this directly

Calls 13

extract_atomFunction · 0.85
members_tokensFunction · 0.85
cloneMethod · 0.80
parse_modeMethod · 0.80
iterMethod · 0.80
is_optionMethod · 0.80
is_lastMethod · 0.80
collectMethod · 0.80
into_iterMethod · 0.80
atom_path_stringMethod · 0.80
spanMethod · 0.45
lenMethod · 0.45

Tested by

no test coverage detected