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
/*!
Implementation details for `sval_derive`.
*/
/*
This library provides a single proc-macro derive that generates `sval::Value` implementations for structs, enums, and newtypes.
It optionally also generates an equivalent `ValueRef` implementation when `#[sval(ref)]` is used.
## Derive expansion
The `derive()` function in the `derive` module classifies the input type and delegates to a specialized handler:
- unit structs become tags.
- single-field tuples become tagged wrappers (or transparent passthroughs).
- multi-field structs become records or tuples, enums become enum streams.
- void enums emit empty matches.
## Attribute parsing
The `attr` module handles `#[sval(...)]` attributes.
Each attribute key has a dedicated struct implementing the `SvalAttribute` trait, which parses the attached expression or literal into a strongly typed result.
Attributes are validated against an allowlist per context (struct, enum, field, etc) to produce clear errors for typos or misplaced attributes.
## Generics and lifetimes
The `bound` module constructs `where` clauses by adding `T: sval::Value` bounds for each type parameter.
The `lifetime` module parses explicit lifetime specifications (with optional bounds) for `ValueRef` derives.
When `#[sval(ref)]` is used without an explicit lifetime, the macro infers it from the type's single lifetime parameter.
## Field streaming strategies
The `value_trait` module defines the `ImplStrategy` trait with two implementations:
- `ImplValue` for `sval::Value`.
- `ImplValueRef` for `sval_ref::ValueRef`.
*/
extern crate quote;
extern crate syn;
extern crate core;
use TokenStream;
use DeriveInput;