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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// Centralized external-crate path resolution for generated code.
//
// Every other codegen file produces token streams that reference items in
// external crates. Funneling those references through this module gives us a
// single fix point if an upstream crate reshuffles its modules
// (`polars::prelude::Foo` → `polars::dtype::Foo` has happened across major
// versions), and lets `proc_macro_crate::crate_name` honour `[package]`
// renames in the downstream `Cargo.toml` so users pinning dependencies under
// different names still get working generated code.
use ;
use TokenStream;
use ;
/// Runtime crate paths used by generated code.
///
/// Default derives point these at the shared dataframe runtime's hidden
/// dependency re-exports so downstream crates do not have to name every
/// implementation dependency directly. Custom trait/columnar runtimes keep
/// using resolved direct dependency roots so their Polars identity stays under
/// the caller's control.
/// Resolve a crate by package name to a `::<resolved-name>` path token, or
/// splice the caller's `fallback` when the crate is not found or refers to
/// the expanding crate itself. This fits generated references to external
/// runtime crates: missing direct deps are best surfaced as `unresolved
/// import ::<name>` at the call site rather than `unresolved name <name>`.
///
/// The default dataframe runtime resolver is bespoke because its
/// `Itself` arm maps to `crate::dataframe` (a substantive path), not to the
/// fallback — a different cascade shape that this helper cannot model
/// cleanly.
pub
/// Token tree for the user-visible `polars` crate root.
///
/// `Itself` and `Err` collapse to `::polars` because the macro doesn't
/// expand inside the polars crate itself in any realistic scenario, and a
/// missing direct dep is better surfaced as `unresolved import ::polars`
/// than `unresolved name polars` — same eventual error, more specific span.
/// `polars::prelude` — namespace for ~all polars items the macro emits.
/// Token tree for the user-visible `polars-arrow` crate root.
///
/// Custom trait/columnar runtimes need a direct `polars-arrow` dependency
/// only when the generated code actually emits public Arrow builders such as
/// `OffsetsBuffer` and `LargeListArray` for list columns. The default runtime
/// instead routes through `dataframe::__private::polars_arrow`.
///
/// `Itself` and `Err` collapse to `::polars_arrow` for the same reason as
/// `polars_root()` — the macro never expands inside `polars-arrow`, and a
/// missing direct dep is best surfaced as `unresolved import
/// ::polars_arrow` at the call site.
/// Dependency roots for custom runtimes. The deriving crate's own `polars`
/// and `polars-arrow` dependencies define the generated code's runtime
/// identity.
/// Dependency roots for the default dataframe runtime. The facade re-exports
/// these from `df_derive::dataframe` and direct-core users get the same shape
/// from `df_derive_core::dataframe`.
/// Token tree for the user-visible `chrono` crate root.
///
/// Chrono field detection accepts bare imports such as `use time_crate::NaiveDate;`
/// when `chrono` has been renamed in `Cargo.toml`. Generated helper calls must
/// therefore resolve the package name the same way Polars paths do, instead of
/// spelling `::chrono` directly.
/// Wrap an inner `DataType` token expression in `layers` `List<>` envelopes
/// at compile time. Returns `inner` unchanged when `layers == 0`. Used by
/// every site that needs to project a leaf logical dtype to its
/// `Vec<…<Vec<leaf>>>` form, where the wrap count is statically known from
/// the wrapper stack: the type-registry full-dtype computation and the
/// encoder's final-assemble per-leaf logical dtype.
pub
/// Emit a runtime `for _ in 0..layers` loop that wraps a runtime `DataType`
/// variable in `layers` `List<>` envelopes. Returns an empty token stream
/// when `layers == 0` so the caller does not emit `for _ in 0..0`, which
/// trips `clippy::reversed_empty_ranges` inside the user's expanded code.
/// Used by the nested schema/empty-frame helpers, where the wrap count is
/// compile-time known but the inner dtype comes from a runtime
/// `T::schema()?` iteration.
pub