@@ -297,15 +297,17 @@ impl<T: AsRef<str>> fmt::Display for Grid<T> {
297
297
// Current position on the line.
298
298
let mut cursor: usize = 0 ;
299
299
for x in 0 ..self . dimensions . widths . len ( ) {
300
- let ( num, next) = match self . options . direction {
300
+ // Calculate position of the current element of the grid
301
+ // in cells and widths vectors and the offset to the next value.
302
+ let ( current, offset) = match self . options . direction {
301
303
Direction :: LeftToRight => ( y * self . dimensions . widths . len ( ) + x, 1 ) ,
302
304
Direction :: TopToBottom => {
303
305
( y + self . dimensions . num_lines * x, self . dimensions . num_lines )
304
306
}
305
307
} ;
306
308
307
309
// Abandon a line mid-way through if that’s where the cells end.
308
- if num >= self . cells . len ( ) {
310
+ if current >= self . cells . len ( ) {
309
311
break ;
310
312
}
311
313
@@ -314,8 +316,8 @@ impl<T: AsRef<str>> fmt::Display for Grid<T> {
314
316
// For this purpose we define next value as well.
315
317
// This prevents printing separator after the actual last value in a row.
316
318
let last_in_row = x == self . dimensions . widths . len ( ) - 1 ;
317
- let contents = & self . cells [ num ] ;
318
- let width = self . widths [ num ] ;
319
+ let contents = & self . cells [ current ] ;
320
+ let width = self . widths [ current ] ;
319
321
let col_width = self . dimensions . widths [ x] ;
320
322
let padding_size = col_width - width;
321
323
@@ -336,7 +338,7 @@ impl<T: AsRef<str>> fmt::Display for Grid<T> {
336
338
337
339
// In case this entry was the last on the current line,
338
340
// there is no need to print the separator and padding.
339
- if last_in_row || num + next >= self . cells . len ( ) {
341
+ if last_in_row || current + offset >= self . cells . len ( ) {
340
342
break ;
341
343
}
342
344
0 commit comments