1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
//! Helpers for resolving default values for enum types.
//!
//! When a struct field has `#[serde(default)]` and its type is an enum,
//! backends need to materialize the default enum variant. This module provides
//! a shared function to extract the default variant name from the IR.
use crate;
use AHashMap;
/// Find the default variant name for an enum.
///
/// Returns the name of the variant marked with `#[default]` if any,
/// otherwise returns the name of the first variant.
///
/// # Arguments
/// - `enum_def`: The enum definition from the IR
///
/// # Returns
/// The name of the default enum variant, or `None` if the enum has no variants.
/// Build a lookup map of enum names to their default variant names.
///
/// This is useful for backends that need to materialize default enum values
/// when a struct field has `#[serde(default)]` but no explicit default value.
///
/// # Arguments
/// - `api`: The API surface containing enum definitions
///
/// # Returns
/// A map from enum name to default variant name. Only enums with variants are included.