pkenum_core 0.3.1

Core logic for pkenum.
Documentation
use syn::{ Ident, ItemEnum, };
use crate::token::EnumVariant;

/// Represents a Rust enum.
pub struct EnumToken {
    /// The name of the enum.
    ///
    /// # Example
    /// `ident` would equate to `IpAddrKind`
    ///
    /// ```
    /// enum IpAddrKind {
    ///     V4,
    ///     V6,
    /// }
    /// ```
    pub ident: Ident,

    /// Variants in the enum.
    ///
    /// # Example
    /// `variants` would equate to `V4` and `V6`.
    ///
    /// ```
    /// enum IpAddrKind {
    ///     V4,
    ///     V6(String),
    /// }
    /// ```
    pub variants: Vec<EnumVariant>,
}

impl EnumToken {
    /// Initiaizes `EnumToken` from `ItemEnum`.
    pub fn from_ast(item: ItemEnum) -> Self {
        EnumToken {
            ident: item.ident,
            variants: item.variants
                .into_iter()
                .map(EnumVariant::from_variant)
                .collect()
        }
    }
}