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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
// What: `use ignore::WalkBuilder;` imports the type that builds a
// filesystem walker honoring `.gitignore`, hidden-file rules,
// and parent-directory ignore files. `ignore` is the crate
// ripgrep uses for its file walking.
// Why: `--all` mode walks the working tree to enumerate every file
// we should scan; `WalkBuilder` does this in parallel and
// respects `.gitignore` semantics (including `!` negations).
// TS map: `import { WalkBuilder } from "<some npm package>"`; there
// is no direct TS analogue; closest is `globby` or
// `fast-glob` with `gitignore: true`.
//
// In TS you'd write (pseudocode):
// ```ts
// import { WalkBuilder } from "<no-direct-equivalent>";
// ```
use WalkBuilder;
// What: `use ignore::WalkState;` imports the enum returned by the
// parallel walker's per-entry callback to control whether to
// keep walking, skip the current subtree, or quit entirely.
// Why: The parallel walker wants the callback to say
// `WalkState::Continue` after handling each entry.
// TS map: No equivalent; closest mental model is "return a status
// code from the callback to steer the iterator."
//
// In TS you'd write (pseudocode):
// ```ts
// // No equivalent; conceptually a return value steering the walker.
// ```
use WalkState;
// What: `use std::sync::{Arc, Mutex};` imports two thread-safe
// wrappers from the standard library.
// - `Arc<T>` ("atomically reference-counted") is a heap-
// allocated `T` whose ownership is shared across multiple
// owners; cloning bumps a refcount, dropping decrements
// it, the inner `T` is freed when the count hits zero.
// - `Mutex<T>` is a mutual-exclusion lock guarding a `T`;
// `lock()` blocks until the current thread is the holder.
// Why: The parallel walker spawns multiple threads, each calling
// our callback concurrently. To collect file paths from all
// threads into a shared `Vec`, we wrap the `Vec` in
// `Arc<Mutex<...>>`: `Arc` to share across threads, `Mutex`
// to serialize push operations.
// TS map: No 1:1 equivalent. Mentally: a JS `Array` shared between
// workers via SharedArrayBuffer + an Atomics lock, except
// the Rust version is type-checked end to end.
// Gotcha: `Arc::clone(&x)` is cheap (atomic increment), NOT a deep
// copy. The pointee is the same `Mutex<Vec>`.
//
// In TS you'd write (pseudocode):
// ```ts
// // No equivalent. Imagine SharedArrayBuffer + a worker-pool lock.
// ```
use ;
// What: `pub fn list_files(root: &str) -> Result<Vec<String>, String>`
// walks the working tree starting at `root` and returns an
// owned vector of file paths (UTF-8). `pub` makes it visible
// to `main.rs`. The signature mirrors the prior
// `list_tracked_files` to keep the call site simple.
// Why: `--all` mode calls this once to get every scannable file.
// The `Result` shape lets us propagate walk errors as
// strings, matching the rest of the binary's error style.
// TS map: `export function listFiles(root: string): string[]`, with
// Rust's `Result<T, String>` standing in for "throw a string
// message instead of returning."
//
// In TS you'd write (pseudocode):
// ```ts
// export function listFiles(root: string): string[] {
// return walkBuilder(root)
// .hidden(false)
// .ignore(false)
// .filterEntry((e) => e.fileName !== ".git" && e.fileName !== ".jj")
// .buildParallel()
// .map((e) => e.path);
// }
// ```