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
//! # struct-mapper-derive
//!
//! Procedural macro crate for `struct-mapper`.
//! Provides `#[derive(MapFrom)]` to auto-generate `impl From<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