Skip to main content

inspect_core/
variant.rs

1//! Enum variant metadata.
2
3#[cfg(not(feature = "std"))]
4use alloc::borrow::Cow;
5#[cfg(feature = "std")]
6use std::borrow::Cow;
7
8/// Metadata about an enum variant.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct VariantInfo<'a> {
11    name: Cow<'a, str>,
12    index: usize,
13}
14
15impl<'a> VariantInfo<'a> {
16    /// Create variant information.
17    pub fn new(name: impl Into<Cow<'a, str>>, index: usize) -> Self {
18        Self { name: name.into(), index }
19    }
20
21    /// The variant's name.
22    pub fn name(&self) -> &str {
23        &self.name
24    }
25
26    /// The variant's discriminant index.
27    pub fn index(&self) -> usize {
28        self.index
29    }
30}