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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// SPDX-FileCopyrightText: 2025 RAprogramm <andrey.rozanov.vl@gmail.com>
//
// SPDX-License-Identifier: MIT
//! Display trait implementation generation for error types.
//!
//! This module provides the core functionality for generating `Display` trait
//! implementations for both struct and enum error types. It handles various
//! display strategies including:
//!
//! - Template-based formatting with placeholder substitution
//! - Transparent delegation to inner fields
//! - Custom formatter function paths
//! - Format argument resolution and projection
//!
//! The module dispatches to specialized implementations based on the error type
//! structure.
use TokenStream;
use Error;
use crate;
use expand_enum;
use expand_struct;
/// Generates Display trait implementation for error types.
///
/// This function serves as the main entry point for Display code generation.
/// It dispatches to struct or enum-specific implementations based on the input
/// type.
///
/// # Arguments
///
/// * `input` - The parsed error type definition containing metadata and
/// structure information
///
/// # Returns
///
/// A `TokenStream` containing the Display trait implementation, or a compile
/// error if generation fails.
///
/// # Examples
///
/// For a struct error:
/// ```ignore
/// #[derive(Error)]
/// #[error("error occurred: {message}")]
/// struct MyError {
/// message: String,
/// }
/// ```
///
/// For an enum error:
/// ```ignore
/// #[derive(Error)]
/// enum MyError {
/// #[error("IO error: {0}")]
/// Io(std::io::Error),
/// }
/// ```