Skip to content
Myr

Rename ind field of Indented

Before adoption: this commit came in with the history the project adopted, so no landing records it.

`ind` was confusingly used for both the number of the whole indented message and the index of the enumerated lines within one message. It is also ambiguous between being short for "index" vs "indent" in the context of an indented writer.

authored by David Tolnay · committed by David Tolnay · parent dedb78c · Browse files · 1 file+10 added−10 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+10 added−10 removed

  • other:+10 added−10 removed

1 file+10 added−10 removed

modified:src/fmt.rs+10 added-10 removed
29 unmodified lines
30 for (n, error) in Chain::new(cause).enumerate() {31 writeln!(f)?;32 let mut indented = Indented {33 inner: f,34 ind: if multiple { Some(n) } else { None },34 number: if multiple { Some(n) } else { None },35 started: false,36 };37 write!(indented, "{}", error)?;38 }
20 unmodified lines
59}6061struct Indented<'a, D> {62 inner: &'a mut D,63 ind: Option<usize>,63 number: Option<usize>,64 started: bool,65}6667impl<T> Write for Indented<'_, T>68where69 T: Write,70{71 fn write_str(&mut self, s: &str) -> fmt::Result {72 for (ind, line) in s.split('\n').enumerate() {72 for (i, line) in s.split('\n').enumerate() {73 if !self.started {74 self.started = true;75 match self.ind {76 Some(ind) => write!(self.inner, "{: >5}: ", ind)?,75 match self.number {76 Some(number) => write!(self.inner, "{: >5}: ", number)?,77 None => self.inner.write_str(" ")?,78 }79 } else if ind > 0 {79 } else if i > 0 {80 self.inner.write_char('\n')?;81 if self.ind.is_some() {81 if self.number.is_some() {82 self.inner.write_str(" ")?;83 } else {84 self.inner.write_str(" ")?;85 }
17 unmodified lines
103 let mut output = String::new();104105 Indented {106 inner: &mut output,107 ind: Some(2),107 number: Some(2),108 started: false,109 }110 .write_str(input)111 .unwrap();
8 unmodified lines
120 let mut output = String::new();121122 Indented {123 inner: &mut output,124 ind: Some(12),124 number: Some(12),125 started: false,126 }127 .write_str(input)128 .unwrap();
8 unmodified lines
137 let mut output = String::new();138139 Indented {140 inner: &mut output,141 ind: None,141 number: None,142 started: false,143 }144 .write_str(input)145 .unwrap();
4 unmodified lines