MCPcopy Create free account
hub / github.com/Lymia/enumset / plan_for_enum

Function plan_for_enum

enumset_derive/src/plan.rs:504–600  ·  view source on GitHub ↗
(input: DeriveInput)

Source from the content-addressed store, hash-verified

502}
503
504pub fn plan_for_enum(input: DeriveInput) -> syn::Result<EnumSetInfo> {
505 let attrs: EnumsetAttrs = EnumsetAttrs::from_derive_input(&input)?;
506
507 if !input.generics.params.is_empty() {
508 error(
509 input.generics.span(),
510 "`#[derive(EnumSetType)]` cannot be used on enums with type parameters.",
511 )
512 } else if let Data::Enum(data) = &input.data {
513 let mut info = EnumSetInfo::new(&input, &attrs);
514
515 // Check enum repr
516 for attr in &input.attrs {
517 if attr.path().is_ident("repr") {
518 let meta: Ident = attr.parse_args()?;
519 let str = meta.to_string();
520 match str.as_str() {
521 "Rust" => {}
522 "C" => info.explicit_enum_repr = Some(Ident::new("u64", Span::call_site())),
523 "u8" | "u16" | "u32" | "u64" | "u128" | "usize" => {
524 info.explicit_enum_repr = Some(Ident::new(str.as_str(), Span::call_site()))
525 }
526 "i8" | "i16" | "i32" | "i64" | "i128" | "isize" => {
527 info.explicit_enum_repr = Some(Ident::new(str.as_str(), Span::call_site()))
528 }
529 x => {
530 error(attr.span(), format!("`#[repr({x})]` is not supported by enumset."))?
531 }
532 }
533 }
534 }
535
536 // Parse internal representations
537 if let Some(repr) = &*attrs.repr {
538 info.push_repr(attrs.repr.span(), repr)?;
539 }
540
541 // Parse serialization representations
542 if let Some(serialize_repr) = &*attrs.serialize_repr {
543 info.push_serialize_repr(attrs.serialize_repr.span(), serialize_repr)?;
544 }
545 if *attrs.serialize_as_map {
546 info.explicit_serde_repr = Some(SerdeRepr::Map);
547 info.warnings.push((
548 attrs.serialize_as_map.span(),
549 "#[enumset(serialize_as_map)] is deprecated. \
550 Use `#[enumset(serialize_repr = \"map\")]` instead.",
551 ));
552 }
553 if *attrs.serialize_as_list {
554 // in old versions, serialize_as_list will override serialize_as_map
555 info.explicit_serde_repr = Some(SerdeRepr::List);
556 info.warnings.push((
557 attrs.serialize_as_list.span(),
558 "#[enumset(serialize_as_list)] is deprecated. \
559 Use `#[enumset(serialize_repr = \"list\")]` instead.",
560 ));
561 }

Callers 1

derive_enum_set_type_0Function · 0.85

Calls 12

errorFunction · 0.85
newFunction · 0.85
is_emptyMethod · 0.80
push_reprMethod · 0.80
push_serialize_reprMethod · 0.80
push_variantMethod · 0.80
map_lsbMethod · 0.80
map_msbMethod · 0.80
map_compactMethod · 0.80
map_masksMethod · 0.80
validateMethod · 0.80
OkEnum · 0.50

Tested by

no test coverage detected