@@ -136,15 +136,18 @@ impl Ord for FileTreeItem {
136
136
137
137
///
138
138
#[ derive( Default ) ]
139
- pub struct FileTreeItems ( Vec < FileTreeItem > ) ;
139
+ pub struct FileTreeItems {
140
+ items : Vec < FileTreeItem > ,
141
+ file_count : usize ,
142
+ }
140
143
141
144
impl FileTreeItems {
142
145
///
143
146
pub ( crate ) fn new (
144
147
list : & [ StatusItem ] ,
145
148
collapsed : & BTreeSet < & String > ,
146
149
) -> Result < Self > {
147
- let mut nodes = Vec :: with_capacity ( list. len ( ) ) ;
150
+ let mut items = Vec :: with_capacity ( list. len ( ) ) ;
148
151
let mut paths_added = BTreeSet :: new ( ) ;
149
152
150
153
for e in list {
@@ -153,26 +156,34 @@ impl FileTreeItems {
153
156
154
157
Self :: push_dirs (
155
158
item_path,
156
- & mut nodes ,
159
+ & mut items ,
157
160
& mut paths_added,
158
161
collapsed,
159
162
) ?;
160
163
}
161
164
162
- nodes . push ( FileTreeItem :: new_file ( e) ?) ;
165
+ items . push ( FileTreeItem :: new_file ( e) ?) ;
163
166
}
164
167
165
- Ok ( Self ( nodes) )
168
+ Ok ( Self {
169
+ items,
170
+ file_count : list. len ( ) ,
171
+ } )
166
172
}
167
173
168
174
///
169
175
pub ( crate ) const fn items ( & self ) -> & Vec < FileTreeItem > {
170
- & self . 0
176
+ & self . items
171
177
}
172
178
173
179
///
174
180
pub ( crate ) fn len ( & self ) -> usize {
175
- self . 0 . len ( )
181
+ self . items . len ( )
182
+ }
183
+
184
+ ///
185
+ pub fn file_count ( & self ) -> usize {
186
+ self . file_count
176
187
}
177
188
178
189
///
@@ -184,7 +195,7 @@ impl FileTreeItems {
184
195
if let Some ( parent_path) = Path :: new ( path) . parent ( ) {
185
196
let parent_path = parent_path. to_str ( ) . unwrap ( ) ;
186
197
for i in ( 0 ..=index) . rev ( ) {
187
- let item = & self . 0 [ i] ;
198
+ let item = & self . items [ i] ;
188
199
let item_path = & item. info . full_path ;
189
200
if item_path == parent_path {
190
201
return i;
@@ -227,15 +238,15 @@ impl FileTreeItems {
227
238
228
239
impl IndexMut < usize > for FileTreeItems {
229
240
fn index_mut ( & mut self , idx : usize ) -> & mut Self :: Output {
230
- & mut self . 0 [ idx]
241
+ & mut self . items [ idx]
231
242
}
232
243
}
233
244
234
245
impl Index < usize > for FileTreeItems {
235
246
type Output = FileTreeItem ;
236
247
237
248
fn index ( & self , idx : usize ) -> & Self :: Output {
238
- & self . 0 [ idx]
249
+ & self . items [ idx]
239
250
}
240
251
}
241
252
@@ -264,7 +275,7 @@ mod tests {
264
275
FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
265
276
266
277
assert_eq ! (
267
- res. 0 ,
278
+ res. items ,
268
279
vec![ FileTreeItem {
269
280
info: TreeItemInfo {
270
281
path: items[ 0 ] . path. clone( ) ,
@@ -284,8 +295,8 @@ mod tests {
284
295
let res =
285
296
FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
286
297
287
- assert_eq ! ( res. 0 . len( ) , 2 ) ;
288
- assert_eq ! ( res. 0 [ 1 ] . info. path, items[ 1 ] . path) ;
298
+ assert_eq ! ( res. items . len( ) , 2 ) ;
299
+ assert_eq ! ( res. items [ 1 ] . info. path, items[ 1 ] . path) ;
289
300
}
290
301
291
302
#[ test]
@@ -296,7 +307,7 @@ mod tests {
296
307
297
308
let res = FileTreeItems :: new ( & items, & BTreeSet :: new ( ) )
298
309
. unwrap ( )
299
- . 0
310
+ . items
300
311
. iter ( )
301
312
. map ( |i| i. info . full_path . clone ( ) )
302
313
. collect :: < Vec < _ > > ( ) ;
@@ -316,7 +327,7 @@ mod tests {
316
327
let list =
317
328
FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
318
329
let mut res = list
319
- . 0
330
+ . items
320
331
. iter ( )
321
332
. map ( |i| ( i. info . indent , i. info . path . as_str ( ) ) ) ;
322
333
@@ -335,7 +346,7 @@ mod tests {
335
346
let list =
336
347
FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
337
348
let mut res = list
338
- . 0
349
+ . items
339
350
. iter ( )
340
351
. map ( |i| ( i. info . indent , i. info . path . as_str ( ) ) ) ;
341
352
@@ -353,7 +364,7 @@ mod tests {
353
364
354
365
let res = FileTreeItems :: new ( & items, & BTreeSet :: new ( ) )
355
366
. unwrap ( )
356
- . 0
367
+ . items
357
368
. iter ( )
358
369
. map ( |i| i. info . full_path . clone ( ) )
359
370
. collect :: < Vec < _ > > ( ) ;
0 commit comments