Skip to content

Commit c725ca3

Browse files
committed
rename postion vars and add comment
1 parent d3d545e commit c725ca3

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -297,15 +297,17 @@ impl<T: AsRef<str>> fmt::Display for Grid<T> {
297297
// Current position on the line.
298298
let mut cursor: usize = 0;
299299
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 {
301303
Direction::LeftToRight => (y * self.dimensions.widths.len() + x, 1),
302304
Direction::TopToBottom => {
303305
(y + self.dimensions.num_lines * x, self.dimensions.num_lines)
304306
}
305307
};
306308

307309
// 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() {
309311
break;
310312
}
311313

@@ -314,8 +316,8 @@ impl<T: AsRef<str>> fmt::Display for Grid<T> {
314316
// For this purpose we define next value as well.
315317
// This prevents printing separator after the actual last value in a row.
316318
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];
319321
let col_width = self.dimensions.widths[x];
320322
let padding_size = col_width - width;
321323

@@ -336,7 +338,7 @@ impl<T: AsRef<str>> fmt::Display for Grid<T> {
336338

337339
// In case this entry was the last on the current line,
338340
// 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() {
340342
break;
341343
}
342344

0 commit comments

Comments
 (0)