/// automatically derived versions, or unintentional behavior may be a result.
/// * `#[enumset(no_ops)` prevents the derive from implementing any operator traits.
/// * `#[enumset(crate_name = "enumset2")]` may be used to change the name of the `enumset` crate
-/// used in the generated code, if you have renamed the crate via cargo options.
+/// used in the generated code. By default enumset parses `Cargo.toml` to determine the name of
+/// the crate, or falls back to `enumset` if it cannot be parsed.
///
/// When the `serde` feature is used, the following features may also be specified. These options
/// may be used (with no effect) when building without the feature enabled:
use proc_macro::TokenStream;
use proc_macro2::{TokenStream as SynTokenStream, Literal, Span};
use std::collections::HashSet;
+use proc_macro_crate::FoundCrate;
use syn::{*, Result, Error};
use syn::spanned::Spanned;
use quote::*;
let name = &info.name;
let enumset = match &info.crate_name {
Some(crate_name) => quote!(::#crate_name),
- None => quote!(::enumset),
+ None => {
+ let crate_name = proc_macro_crate::crate_name("enumset");
+ match crate_name {
+ Ok(FoundCrate::Name(name)) => {
+ let ident = Ident::new(&name, Span::call_site());
+ quote!(::#ident)
+ }
+ _ => quote!(::enumset),
+ }
+ },
};
let typed_enumset = quote!(#enumset::EnumSet<#name>);
let core = quote!(#enumset::__internal::core_export);