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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
//! # struct-mapper-derive
//!
//! Procedural macro crate for `struct-mapper`.
//! Provides `#[derive(MapFrom)]` and `#[derive(TryMapFrom)]` to auto-generate
//! `impl From<Source> for Target` and `impl TryFrom<Source> for Target`.
//!
//! **Do not depend on this crate directly.** Use `struct-mapper` instead.
use TokenStream;
use ;
/// Derive macro that generates `impl From<Source> for Target` by mapping fields.
///
/// # Usage
///
/// ```rust,ignore
/// use struct_mapper::MapFrom;
///
/// struct UserEntity {
/// name: String,
/// email: String,
/// }
///
/// #[derive(MapFrom)]
/// #[map_from(UserEntity)]
/// struct UserResponse {
/// name: String,
/// email: String,
/// }
///
/// // Now you can do:
/// let entity = UserEntity { name: "Alice".into(), email: "a@b.com".into() };
/// let response: UserResponse = entity.into();
/// ```
///
/// # Field Attributes
///
/// - `#[map(from = "source_field")]` — Map from a differently-named source field
/// - `#[map(skip, default)]` — Skip this field, use `Default::default()`
/// - `#[map(into)]` — Call `.into()` on the source field value
/// - `#[map(with = "path::to::fn")]` — Apply a custom conversion function
/// Derive macro that generates `impl TryFrom<Source> for Target` by mapping fields.
///
/// Use this when one or more field conversions can fail (e.g., type narrowing,
/// parsing, validation). The generated implementation returns
/// `Result<Self, struct_mapper::MapError>`.
///
/// # Usage
///
/// ```rust,ignore
/// use struct_mapper::TryMapFrom;
///
/// struct RawInput {
/// count: i64,
/// name: String,
/// }
///
/// #[derive(TryMapFrom)]
/// #[try_map_from(RawInput)]
/// struct ValidInput {
/// #[map(try_into)]
/// count: u32, // i64 -> u32 can fail
/// name: String, // direct (infallible)
/// }
///
/// // Now you can do:
/// let raw = RawInput { count: 42, name: "Alice".into() };
/// let valid: ValidInput = raw.try_into().unwrap();
/// ```
///
/// # Field Attributes
///
/// All `MapFrom` attributes work here, plus:
///
/// - `#[map(try_into)]` — Call `.try_into()` on the source field (fallible)
/// - `#[map(try_with = "path::to::fn")]` — Apply a fallible conversion function