pubfn from_repr_inner(ast: &DeriveInput) -> syn::Result<TokenStream> { let name = &ast.ident; letgen = &ast.generics; let (impl_generics, ty_generics, where_clause) = gen.split_for_impl(); let vis = &ast.vis;
letmut discriminant_type: Type = syn::parse("usize".parse().unwrap()).unwrap(); iflet Some(type_path) = ast
.get_type_properties()
.ok()
.and_then(|tp| tp.enum_repr)
.and_then(|repr_ts| syn::parse2::<Type>(repr_ts).ok())
{ ifletType::Path(path) = type_path.clone() { iflet Some(seg) = path.path.segments.last() { for t in &[ "u8", "u16", "u32", "u64", "usize", "i8", "i16", "i32", "i64", "isize",
] { if seg.ident == t {
discriminant_type = type_path; break;
}
}
}
}
}
ifgen.lifetimes().count() > 0 { return Err(syn::Error::new(
Span::call_site(), "This macro doesn't support enums with lifetimes. \
The resulting enums would be unbounded.",
));
}
let variants = match &ast.data {
Data::Enum(v) => &v.variants,
_ => return Err(non_enum_error()),
};
letmut arms = Vec::new(); letmut constant_defs = Vec::new(); letmut has_additional_data = false; letmut prev_const_var_ident = None; for variant in variants { if variant.get_variant_properties()?.disabled.is_some() { continue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.