inspect-core 0.1.0

Core types and traits for the inspect-rs introspection system
Documentation
//! Enum variant metadata.

#[cfg(not(feature = "std"))]
use alloc::borrow::Cow;
#[cfg(feature = "std")]
use std::borrow::Cow;

/// Metadata about an enum variant.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct VariantInfo<'a> {
    name: Cow<'a, str>,
    index: usize,
}

impl<'a> VariantInfo<'a> {
    /// Create variant information.
    pub fn new(name: impl Into<Cow<'a, str>>, index: usize) -> Self {
        Self { name: name.into(), index }
    }

    /// The variant's name.
    pub fn name(&self) -> &str {
        &self.name
    }

    /// The variant's discriminant index.
    pub fn index(&self) -> usize {
        self.index
    }
}