@@ -136,15 +136,18 @@ impl Ord for FileTreeItem {
136136
137137///
138138#[ derive( Default ) ]
139- pub struct FileTreeItems ( Vec < FileTreeItem > ) ;
139+ pub struct FileTreeItems {
140+ items : Vec < FileTreeItem > ,
141+ file_count : usize ,
142+ }
140143
141144impl FileTreeItems {
142145 ///
143146 pub ( crate ) fn new (
144147 list : & [ StatusItem ] ,
145148 collapsed : & BTreeSet < & String > ,
146149 ) -> Result < Self > {
147- let mut nodes = Vec :: with_capacity ( list. len ( ) ) ;
150+ let mut items = Vec :: with_capacity ( list. len ( ) ) ;
148151 let mut paths_added = BTreeSet :: new ( ) ;
149152
150153 for e in list {
@@ -153,26 +156,34 @@ impl FileTreeItems {
153156
154157 Self :: push_dirs (
155158 item_path,
156- & mut nodes ,
159+ & mut items ,
157160 & mut paths_added,
158161 collapsed,
159162 ) ?;
160163 }
161164
162- nodes . push ( FileTreeItem :: new_file ( e) ?) ;
165+ items . push ( FileTreeItem :: new_file ( e) ?) ;
163166 }
164167
165- Ok ( Self ( nodes) )
168+ Ok ( Self {
169+ items,
170+ file_count : list. len ( ) ,
171+ } )
166172 }
167173
168174 ///
169175 pub ( crate ) const fn items ( & self ) -> & Vec < FileTreeItem > {
170- & self . 0
176+ & self . items
171177 }
172178
173179 ///
174180 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
176187 }
177188
178189 ///
@@ -184,7 +195,7 @@ impl FileTreeItems {
184195 if let Some ( parent_path) = Path :: new ( path) . parent ( ) {
185196 let parent_path = parent_path. to_str ( ) . unwrap ( ) ;
186197 for i in ( 0 ..=index) . rev ( ) {
187- let item = & self . 0 [ i] ;
198+ let item = & self . items [ i] ;
188199 let item_path = & item. info . full_path ;
189200 if item_path == parent_path {
190201 return i;
@@ -227,15 +238,15 @@ impl FileTreeItems {
227238
228239impl IndexMut < usize > for FileTreeItems {
229240 fn index_mut ( & mut self , idx : usize ) -> & mut Self :: Output {
230- & mut self . 0 [ idx]
241+ & mut self . items [ idx]
231242 }
232243}
233244
234245impl Index < usize > for FileTreeItems {
235246 type Output = FileTreeItem ;
236247
237248 fn index ( & self , idx : usize ) -> & Self :: Output {
238- & self . 0 [ idx]
249+ & self . items [ idx]
239250 }
240251}
241252
@@ -264,7 +275,7 @@ mod tests {
264275 FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
265276
266277 assert_eq ! (
267- res. 0 ,
278+ res. items ,
268279 vec![ FileTreeItem {
269280 info: TreeItemInfo {
270281 path: items[ 0 ] . path. clone( ) ,
@@ -284,8 +295,8 @@ mod tests {
284295 let res =
285296 FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
286297
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) ;
289300 }
290301
291302 #[ test]
@@ -296,7 +307,7 @@ mod tests {
296307
297308 let res = FileTreeItems :: new ( & items, & BTreeSet :: new ( ) )
298309 . unwrap ( )
299- . 0
310+ . items
300311 . iter ( )
301312 . map ( |i| i. info . full_path . clone ( ) )
302313 . collect :: < Vec < _ > > ( ) ;
@@ -316,7 +327,7 @@ mod tests {
316327 let list =
317328 FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
318329 let mut res = list
319- . 0
330+ . items
320331 . iter ( )
321332 . map ( |i| ( i. info . indent , i. info . path . as_str ( ) ) ) ;
322333
@@ -335,7 +346,7 @@ mod tests {
335346 let list =
336347 FileTreeItems :: new ( & items, & BTreeSet :: new ( ) ) . unwrap ( ) ;
337348 let mut res = list
338- . 0
349+ . items
339350 . iter ( )
340351 . map ( |i| ( i. info . indent , i. info . path . as_str ( ) ) ) ;
341352
@@ -353,7 +364,7 @@ mod tests {
353364
354365 let res = FileTreeItems :: new ( & items, & BTreeSet :: new ( ) )
355366 . unwrap ( )
356- . 0
367+ . items
357368 . iter ( )
358369 . map ( |i| i. info . full_path . clone ( ) )
359370 . collect :: < Vec < _ > > ( ) ;
0 commit comments