| 1 | //! This crate provides an implementation of |
| 2 | //! [elastic tabstops](http://nickgravgaard.com/elastictabstops/index.html). |
| 3 | //! It is a minimal port of Go's |
| 4 | //! [tabwriter](http://golang.org/pkg/text/tabwriter/) package. |
| 5 | //! Namely, its main mode of operation is to wrap a `Writer` and implement |
| 6 | //! elastic tabstops for the text written to the wrapped `Writer`. |
| 7 | //! |
| 8 | //! This package is also bundled with a program, `tabwriter`, |
| 9 | //! that exposes this functionality at the command line. |
| 10 | //! |
| 11 | //! Here's an example that shows basic alignment: |
| 12 | //! |
| 13 | //! ```rust |
| 14 | //! use std::io::Write; |
| 15 | //! use tabwriter::TabWriter; |
| 16 | //! |
| 17 | //! let mut tw = TabWriter::new(vec![]); |
| 18 | //! write!(&mut tw, " |
| 19 | //! Bruce Springsteen\tBorn to Run |
| 20 | //! Bob Seger\tNight Moves |
| 21 | //! Metallica\tBlack |
| 22 | //! The Boss\tDarkness on the Edge of Town |
| 23 | //! ").unwrap(); |
| 24 | //! tw.flush().unwrap(); |
| 25 | //! |
| 26 | //! let written = String::from_utf8(tw.into_inner().unwrap()).unwrap(); |
| 27 | //! assert_eq!(&*written, " |
| 28 | //! Bruce Springsteen Born to Run |
| 29 | //! Bob Seger Night Moves |
| 30 | //! Metallica Black |
| 31 | //! The Boss Darkness on the Edge of Town |
| 32 | //! "); |
| 33 | //! ``` |
| 34 | //! |
| 35 | //! Note that `flush` **must** be called or else `TabWriter` may never write |
| 36 | //! anything. This is because elastic tabstops requires knowing about future |
| 37 | //! lines in order to align output. More precisely, all text considered in a |
| 38 | //! single alignment must fit into memory. |
| 39 | //! |
| 40 | //! Here's another example that demonstrates how *only* contiguous columns |
| 41 | //! are aligned: |
| 42 | //! |
| 43 | //! ```rust |
| 44 | //! use std::io::Write; |
| 45 | //! use tabwriter::TabWriter; |
| 46 | //! |
| 47 | //! let mut tw = TabWriter::new(vec![]).padding(1); |
| 48 | //! write!(&mut tw, " |
| 49 | //!fn foobar() {{ |
| 50 | //! let mut x = 1+1;\t// addition |
| 51 | //! x += 1;\t// increment in place |
| 52 | //! let y = x * x * x * x;\t// multiply! |
| 53 | //! |
| 54 | //! y += 1;\t// this is another group |
| 55 | //! y += 2 * 2;\t// that is separately aligned |
| 56 | //!}} |
| 57 | //!").unwrap(); |
| 58 | //! tw.flush().unwrap(); |
| 59 | //! |
| 60 | //! let written = String::from_utf8(tw.into_inner().unwrap()).unwrap(); |
| 61 | //! assert_eq!(&*written, " |
| 62 | //!fn foobar() { |
| 63 | //! let mut x = 1+1; // addition |
| 64 | //! x += 1; // increment in place |
| 65 | //! let y = x * x * x * x; // multiply! |
| 66 | //! |
| 67 | //! y += 1; // this is another group |
| 68 | //! y += 2 * 2; // that is separately aligned |
| 69 | //!} |
| 70 | //!"); |
| 71 | //! ``` |
| 72 | |
| 73 | #![deny(missing_docs)] |
| 74 | |
| 75 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/; |
| 76 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/; |
| 77 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/; |
| 78 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::{selfrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/, Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#}; |
| 79 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/; |
| 80 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/; |
| 81 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/; |
| 82 | |
| 83 | #[cfg(test)] |
| 84 | mod testrust-analyzer cargo tabwriter 1.4.1 test/; |
| 85 | |
| 86 | /// TabWriter wraps an arbitrary writer and aligns tabbed output. |
| 87 | /// |
| 88 | /// Elastic tabstops work by aligning *contiguous* tabbed delimited fields |
| 89 | /// known as *column blocks*. When a line appears that breaks all contiguous |
| 90 | /// blocks, all buffered output will be flushed to the underlying writer. |
| 91 | /// Otherwise, output will stay buffered until `flush` is explicitly called. |
| 92 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 93 | pub struct TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 94 | wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w.: W, |
| 95 | bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf.: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u8>>, |
| 96 | linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Cellrust-analyzer cargo tabwriter 1.4.1 Cell#>>, |
| 97 | curcellrust-analyzer cargo tabwriter 1.4.1 TabWriter#curcell.: Cellrust-analyzer cargo tabwriter 1.4.1 Cell#, |
| 98 | minwidthrust-analyzer cargo tabwriter 1.4.1 TabWriter#minwidth.: usize, |
| 99 | paddingrust-analyzer cargo tabwriter 1.4.1 TabWriter#padding.: usize, |
| 100 | alignmentrust-analyzer cargo tabwriter 1.4.1 TabWriter#alignment.: Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment#, |
| 101 | ansirust-analyzer cargo tabwriter 1.4.1 TabWriter#ansi.: bool, |
| 102 | tab_indentrust-analyzer cargo tabwriter 1.4.1 TabWriter#tab_indent.: bool, |
| 103 | } |
| 104 | |
| 105 | /// `Alignment` represents how a `TabWriter` should align text within its cell. |
| 106 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 107 | pub enum Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment# { |
| 108 | /// Text should be aligned with the left edge of the cell |
| 109 | Leftrust-analyzer cargo tabwriter 1.4.1 Alignment#Left#, |
| 110 | /// Text should be centered within the cell |
| 111 | Centerrust-analyzer cargo tabwriter 1.4.1 Alignment#Center#, |
| 112 | /// Text should be aligned with the right edge of the cell |
| 113 | Rightrust-analyzer cargo tabwriter 1.4.1 Alignment#Right#, |
| 114 | } |
| 115 | |
| 116 | #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:)] |
| 117 | struct Cellrust-analyzer cargo tabwriter 1.4.1 Cell# { |
| 118 | startrust-analyzer cargo tabwriter 1.4.1 Cell#start.: usize, // offset into TabWriter.buf |
| 119 | widthrust-analyzer cargo tabwriter 1.4.1 Cell#width.: usize, // in characters |
| 120 | sizerust-analyzer cargo tabwriter 1.4.1 Cell#size.: usize, // in bytes |
| 121 | } |
| 122 | |
| 123 | impl<W: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 124 | /// Create a new `TabWriter` from an existing `Writer`. |
| 125 | /// |
| 126 | /// All output written to `Writer` is passed through `TabWriter`. |
| 127 | /// Contiguous column blocks indicated by tabs are aligned. |
| 128 | /// |
| 129 | /// Note that `flush` must be called to guarantee that `TabWriter` will |
| 130 | /// write to the given writer. |
| 131 | pub fn newrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]new().(w: W) -> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 132 | TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter# { |
| 133 | wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w., |
| 134 | bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf.: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(1024)), |
| 135 | linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines.: vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]], |
| 136 | curcellrust-analyzer cargo tabwriter 1.4.1 TabWriter#curcell.: Cellrust-analyzer cargo tabwriter 1.4.1 Cell#::newrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]new().(0), |
| 137 | minwidthrust-analyzer cargo tabwriter 1.4.1 TabWriter#minwidth.: 2, |
| 138 | paddingrust-analyzer cargo tabwriter 1.4.1 TabWriter#padding.: 2, |
| 139 | alignmentrust-analyzer cargo tabwriter 1.4.1 TabWriter#alignment.: Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment#::Leftrust-analyzer cargo tabwriter 1.4.1 Alignment#Left#, |
| 140 | ansirust-analyzer cargo tabwriter 1.4.1 TabWriter#ansi.: cfgrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/cfg!!(feature = "ansi_formatting"), |
| 141 | tab_indentrust-analyzer cargo tabwriter 1.4.1 TabWriter#tab_indent.: false, |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | /// Set the minimum width of each column. That is, all columns will have |
| 146 | /// *at least* the size given here. If a column is smaller than `minwidth`, |
| 147 | /// then it is padded with spaces. |
| 148 | /// |
| 149 | /// The default minimum width is `2`. |
| 150 | pub fn minwidthrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]minwidth().(mut self, minwidth: usize) -> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 151 | self.minwidthrust-analyzer cargo tabwriter 1.4.1 TabWriter#minwidth. = minwidth; |
| 152 | self |
| 153 | } |
| 154 | |
| 155 | /// Set the padding between columns. All columns will be separated by |
| 156 | /// *at least* the number of spaces indicated by `padding`. If `padding` |
| 157 | /// is zero, then columns may run up against each other without any |
| 158 | /// separation. |
| 159 | /// |
| 160 | /// The default padding is `2`. |
| 161 | pub fn paddingrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]padding().(mut self, padding: usize) -> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 162 | self.paddingrust-analyzer cargo tabwriter 1.4.1 TabWriter#padding. = padding; |
| 163 | self |
| 164 | } |
| 165 | |
| 166 | /// Set the alignment of text within cells. This will effect future flushes. |
| 167 | /// |
| 168 | /// The default alignment is `Alignment::Left`. |
| 169 | pub fn alignmentrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]alignment().(mut self, alignment: Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment#) -> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 170 | self.alignmentrust-analyzer cargo tabwriter 1.4.1 TabWriter#alignment. = alignment; |
| 171 | self |
| 172 | } |
| 173 | |
| 174 | /// Ignore ANSI escape codes when computing the number of display columns. |
| 175 | /// |
| 176 | /// This is disabled by default. (But is enabled by default when the |
| 177 | /// deprecated `ansi_formatting` crate feature is enabled.) |
| 178 | pub fn ansirust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]ansi().(mut self, yes: bool) -> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 179 | self.ansirust-analyzer cargo tabwriter 1.4.1 TabWriter#ansi. = yes; |
| 180 | self |
| 181 | } |
| 182 | |
| 183 | /// Always use tabs for indentation columns (i.e., padding of |
| 184 | /// leading empty cells on the left). |
| 185 | /// |
| 186 | /// This is disabled by default. |
| 187 | pub fn tab_indentrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]tab_indent().(mut self, yes: bool) -> TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 188 | self.tab_indentrust-analyzer cargo tabwriter 1.4.1 TabWriter#tab_indent. = yes; |
| 189 | self |
| 190 | } |
| 191 | |
| 192 | /// Unwraps this `TabWriter`, returning the underlying writer. |
| 193 | /// |
| 194 | /// This internal buffer is flushed before returning the writer. If the |
| 195 | /// flush fails, then an error is returned. |
| 196 | pub fn into_innerrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]into_inner().(mut self) -> Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#<W, IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#<TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W>>> { |
| 197 | match self.flushrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`][Write]flush().() { |
| 198 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w.), |
| 199 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(err) => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#(self, err)), |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | /// Resets the state of the aligner. Once the aligner is reset, all future |
| 204 | /// writes will start producing a new alignment. |
| 205 | fn resetrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]reset().(&mut self) { |
| 206 | self.bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf. = iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Cursorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/Cursor#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]new().(Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]with_capacity().(1024)); |
| 207 | self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines. = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]]; |
| 208 | self.curcellrust-analyzer cargo tabwriter 1.4.1 TabWriter#curcell. = Cellrust-analyzer cargo tabwriter 1.4.1 Cell#::newrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]new().(0); |
| 209 | } |
| 210 | |
| 211 | /// Adds the bytes received into the buffer and updates the size of |
| 212 | /// the current cell. |
| 213 | fn add_bytesrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]add_bytes().(&mut self, bytes: &[u8]) { |
| 214 | self.curcellrust-analyzer cargo tabwriter 1.4.1 TabWriter#curcell..sizerust-analyzer cargo tabwriter 1.4.1 Cell#size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 215 | let _ = self.bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<Vec<u8, A>>`][Write]write_all().(bytes); // cannot fail |
| 216 | } |
| 217 | |
| 218 | /// Ends the current cell, updates the UTF8 width of the cell and starts |
| 219 | /// a fresh cell. |
| 220 | fn term_curcellrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]term_curcell().(&mut self) { |
| 221 | let mut curcell = Cellrust-analyzer cargo tabwriter 1.4.1 Cell#::newrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]new().(self.bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf..positionrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]position().() as usize); |
| 222 | memrust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/::swaprust-analyzer cargo core https://github.com/rust-lang/rust/library/core mem/swap().(&mut self.curcellrust-analyzer cargo tabwriter 1.4.1 TabWriter#curcell., &mut curcell); |
| 223 | |
| 224 | if self.ansirust-analyzer cargo tabwriter 1.4.1 TabWriter#ansi. { |
| 225 | curcell.update_widthrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]update_width().(&self.bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf..get_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]get_ref().(), count_columns_ansirust-analyzer cargo tabwriter 1.4.1 count_columns_ansi().); |
| 226 | } else { |
| 227 | curcell.update_widthrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]update_width().(&self.bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf..get_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]get_ref().(), count_columns_noansirust-analyzer cargo tabwriter 1.4.1 count_columns_noansi().); |
| 228 | } |
| 229 | self.curline_mutrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]curline_mut().().pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(curcell); |
| 230 | } |
| 231 | |
| 232 | /// Return a view of the current line of cells. |
| 233 | fn curlinerust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]curline().(&mut self) -> &[Cellrust-analyzer cargo tabwriter 1.4.1 Cell#] { |
| 234 | let i = self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1; |
| 235 | &*rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][Deref]deref().self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index(). |
| 236 | } |
| 237 | |
| 238 | /// Return a mutable view of the current line of cells. |
| 239 | fn curline_mutrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]curline_mut().(&mut self) -> &mut Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Cellrust-analyzer cargo tabwriter 1.4.1 Cell#> { |
| 240 | let i = self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1; |
| 241 | &mut self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines.[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut(). |
| 242 | } |
| 243 | } |
| 244 | |
| 245 | impl Cellrust-analyzer cargo tabwriter 1.4.1 Cell# { |
| 246 | fn newrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]new().(start: usize) -> Cellrust-analyzer cargo tabwriter 1.4.1 Cell# { |
| 247 | Cellrust-analyzer cargo tabwriter 1.4.1 Cell# { startrust-analyzer cargo tabwriter 1.4.1 Cell#start., widthrust-analyzer cargo tabwriter 1.4.1 Cell#width.: 0, sizerust-analyzer cargo tabwriter 1.4.1 Cell#size.: 0 } |
| 248 | } |
| 249 | |
| 250 | fn update_widthrust-analyzer cargo tabwriter 1.4.1 impl#[Cell]update_width().( |
| 251 | &mut self, |
| 252 | buf: &[u8], |
| 253 | count_columns: impl Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(&[u8]) -> usize, |
| 254 | ) { |
| 255 | let end = self.startrust-analyzer cargo tabwriter 1.4.1 Cell#start. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.sizerust-analyzer cargo tabwriter 1.4.1 Cell#size.; |
| 256 | self.widthrust-analyzer cargo tabwriter 1.4.1 Cell#width. = count_columns(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().self.startrust-analyzer cargo tabwriter 1.4.1 Cell#start...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 257 | } |
| 258 | } |
| 259 | |
| 260 | impl<W: iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Writerust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write# for TabWriterrust-analyzer cargo tabwriter 1.4.1 TabWriter#<W> { |
| 261 | fn writerust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`][Write]write().(&mut self, buf: &[u8]) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<usize> { |
| 262 | let mut lastterm = 0usize; |
| 263 | for (i, &c) in buf.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 264 | match c { |
| 265 | b'\t' | b'\n' => { |
| 266 | self.add_bytesrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]add_bytes().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().lastterm..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 267 | self.term_curcellrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]term_curcell().(); |
| 268 | lastterm = i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 269 | if c rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u8][`PartialEq<Self>`]eq().b'\n' { |
| 270 | let ncells = self.curlinerust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]curline().().lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(); |
| 271 | self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]); |
| 272 | // Having a single cell means that *all* previous |
| 273 | // columns have been broken, so we should just flush. |
| 274 | if ncells rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().1 { |
| 275 | self.flushrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`][Write]flush().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 276 | } |
| 277 | } |
| 278 | } |
| 279 | _ => {} |
| 280 | } |
| 281 | } |
| 282 | self.add_bytesrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]add_bytes().(&buf[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().lastterm..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 283 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(buf.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().()) |
| 284 | } |
| 285 | |
| 286 | fn flushrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`][Write]flush().(&mut self) -> iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Resultrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Result#<()> { |
| 287 | if self.curcellrust-analyzer cargo tabwriter 1.4.1 TabWriter#curcell..sizerust-analyzer cargo tabwriter 1.4.1 Cell#size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().>rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]gt().0 { |
| 288 | self.term_curcellrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]term_curcell().(); |
| 289 | } |
| 290 | let widths = cell_widthsrust-analyzer cargo tabwriter 1.4.1 cell_widths().(&self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines., self.minwidthrust-analyzer cargo tabwriter 1.4.1 TabWriter#minwidth.); |
| 291 | |
| 292 | // This is a trick to avoid allocating padding for every cell. |
| 293 | // Just allocate the most we'll ever need and borrow from it. |
| 294 | let biggest_width = widths |
| 295 | .iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() |
| 296 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|ws| ws.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|&w| w).maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#max().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0)) |
| 297 | .maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#max().() |
| 298 | .unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0); |
| 299 | let padding: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# = |
| 300 | iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::repeatrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/repeat/repeat().(' ').takerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#take().(biggest_width rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().self.paddingrust-analyzer cargo tabwriter 1.4.1 TabWriter#padding.).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 301 | |
| 302 | let mut first = true; |
| 303 | for (line, widths) in self.linesrust-analyzer cargo tabwriter 1.4.1 TabWriter#lines..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().ziprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#zip().(widths.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()) { |
| 304 | if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().first { |
| 305 | self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(b"\n")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 306 | } else { |
| 307 | first = false |
| 308 | } |
| 309 | |
| 310 | let mut use_tabs = self.tab_indentrust-analyzer cargo tabwriter 1.4.1 TabWriter#tab_indent.; |
| 311 | for (i, cell) in line.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 312 | let bytes = |
| 313 | &self.bufrust-analyzer cargo tabwriter 1.4.1 TabWriter#buf..get_refrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/cursor/impl#[`Cursor<T>`]get_ref().()[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().cell.startrust-analyzer cargo tabwriter 1.4.1 Cell#start...rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#cell.startrust-analyzer cargo tabwriter 1.4.1 Cell#start. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().cell.sizerust-analyzer cargo tabwriter 1.4.1 Cell#size.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().; |
| 314 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().widths.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 315 | // There is no width for the last column |
| 316 | assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(i, line.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() -rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). 1); |
| 317 | self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 318 | } else { |
| 319 | if use_tabs && cell.sizerust-analyzer cargo tabwriter 1.4.1 Cell#size. rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 320 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w., "\t")?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 321 | continue; |
| 322 | } |
| 323 | use_tabs = false; |
| 324 | |
| 325 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(widths[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). >= cell.widthrust-analyzer cargo tabwriter 1.4.1 Cell#width.); |
| 326 | let extra_space = widths[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().cell.widthrust-analyzer cargo tabwriter 1.4.1 Cell#width.; |
| 327 | let (left_spaces, mut right_spaces) = match self.alignmentrust-analyzer cargo tabwriter 1.4.1 TabWriter#alignment. |
| 328 | { |
| 329 | Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment#::Leftrust-analyzer cargo tabwriter 1.4.1 Alignment#Left# => (0, extra_space), |
| 330 | Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment#::Rightrust-analyzer cargo tabwriter 1.4.1 Alignment#Right# => (extra_space, 0), |
| 331 | Alignmentrust-analyzer cargo tabwriter 1.4.1 Alignment#::Centerrust-analyzer cargo tabwriter 1.4.1 Alignment#Center# => { |
| 332 | (extra_space rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2, extra_space rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().extra_space rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div()./rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Div<Self>`]div().2) |
| 333 | } |
| 334 | }; |
| 335 | right_spaces rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().self.paddingrust-analyzer cargo tabwriter 1.4.1 TabWriter#padding.; |
| 336 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w., "{}", &padding[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().0..left_spaces]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 337 | self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w..write_allrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/Write#write_all().(bytes)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 338 | writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(&mut self.wrust-analyzer cargo tabwriter 1.4.1 TabWriter#w., "{}", &padding[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().0..right_spaces]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 339 | } |
| 340 | } |
| 341 | } |
| 342 | |
| 343 | self.resetrust-analyzer cargo tabwriter 1.4.1 impl#[`TabWriter<W>`]reset().(); |
| 344 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(()) |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /// An error returned by `into_inner`. |
| 349 | /// |
| 350 | /// This combines the error that happened while flushing the buffer with the |
| 351 | /// `TabWriter` itself. |
| 352 | pub struct IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#<W>(W, iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error#); |
| 353 | |
| 354 | impl<W> IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#<W> { |
| 355 | /// Returns the error which caused the `into_error()` call to fail. |
| 356 | pub fn errorrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`]error().(&self) -> &iorust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/::Errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/Error# { |
| 357 | &self.1rust-analyzer cargo tabwriter 1.4.1 IntoInnerError#1. |
| 358 | } |
| 359 | |
| 360 | /// Returns the `TabWriter` instance which generated the error. |
| 361 | pub fn into_innerrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`]into_inner().(self) -> W { |
| 362 | self.0rust-analyzer cargo tabwriter 1.4.1 IntoInnerError#0. |
| 363 | } |
| 364 | } |
| 365 | |
| 366 | impl<W> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Debug# for IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#<W> { |
| 367 | fn fmtrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`][Debug]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 368 | self.errorrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`]error().().fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][Debug]fmt().(f) |
| 369 | } |
| 370 | } |
| 371 | |
| 372 | impl<W> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Displayrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Display# for IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#<W> { |
| 373 | fn fmtrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`][Display]fmt().(&self, f: &mut fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Formatterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Formatter#<'_>) -> fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/::Resultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/Result# { |
| 374 | self.errorrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`]error().().fmtrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/error/impl#[Error][Display]fmt().(f) |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | impl<W: ::stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/::Anyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core any/Any#> errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error# for IntoInnerErrorrust-analyzer cargo tabwriter 1.4.1 IntoInnerError#<W> { |
| 379 | #[allow(deprecated)] |
| 380 | fn descriptionrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`][Error]description().(&self) -> &str { |
| 381 | self.errorrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`]error().().descriptionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#description().() |
| 382 | } |
| 383 | |
| 384 | fn causerust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`][Error]cause().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&dyn errorrust-analyzer cargo std https://github.com/rust-lang/rust/library/std error/::Errorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core error/Error#> { |
| 385 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.errorrust-analyzer cargo tabwriter 1.4.1 impl#[`IntoInnerError<W>`]error().()) |
| 386 | } |
| 387 | } |
| 388 | |
| 389 | fn cell_widthsrust-analyzer cargo tabwriter 1.4.1 cell_widths().(lines: &Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Cellrust-analyzer cargo tabwriter 1.4.1 Cell#>>, minwidth: usize) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<usize>> { |
| 390 | // Naively, this algorithm looks like it could be O(n^2m) where `n` is |
| 391 | // the number of lines and `m` is the number of contiguous columns. |
| 392 | // |
| 393 | // However, I claim that it is actually O(nm). That is, the width for |
| 394 | // every contiguous column is computed exactly once. |
| 395 | let mut ws: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_> = (0..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#lines.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()).maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|_| vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![]).collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().(); |
| 396 | for (i, iline) in lines.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 397 | if iline.is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().() { |
| 398 | continue; |
| 399 | } |
| 400 | for col in ws[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index().i]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Index<I>`]index()..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(iline.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1) { |
| 401 | let mut width = minwidth; |
| 402 | let mut contig_count = 0; |
| 403 | for line in lines[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().i..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() { |
| 404 | if col rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1 rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().line.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() { |
| 405 | // ignores last column |
| 406 | break; |
| 407 | } |
| 408 | contig_count rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().+=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`AddAssign<Self>`]add_assign().1; |
| 409 | width = cmprust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(width, line[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().col]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..widthrust-analyzer cargo tabwriter 1.4.1 Cell#width.); |
| 410 | } |
| 411 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(contig_count >= 1); |
| 412 | for j in i..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#(i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().contig_count) { |
| 413 | ws[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut().j]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`IndexMut<I>`]index_mut()..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(width); |
| 414 | } |
| 415 | } |
| 416 | } |
| 417 | ws |
| 418 | } |
| 419 | |
| 420 | fn count_columns_noansirust-analyzer cargo tabwriter 1.4.1 count_columns_noansi().(bytes: &[u8]) -> usize { |
| 421 | use unicode_widthrust-analyzer cargo unicode-width 0.2.2 crate/::UnicodeWidthCharrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthChar#; |
| 422 | |
| 423 | // If we have a Unicode string, then attempt to guess the number of |
| 424 | // *display* columns used. |
| 425 | match strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(bytes) { |
| 426 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 427 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => s |
| 428 | .charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() |
| 429 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| UnicodeWidthCharrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthChar#::widthrust-analyzer cargo unicode-width 0.2.2 impl#[char][UnicodeWidthChar]width().(c).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0)) |
| 430 | .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]fold().(0, |sum, width| sum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().width), |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | fn count_columns_ansirust-analyzer cargo tabwriter 1.4.1 count_columns_ansi().(bytes: &[u8]) -> usize { |
| 435 | use unicode_widthrust-analyzer cargo unicode-width 0.2.2 crate/::UnicodeWidthCharrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthChar#; |
| 436 | |
| 437 | // If we have a Unicode string, then attempt to guess the number of |
| 438 | // *display* columns used. |
| 439 | match strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/::from_utf8rust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/converts/from_utf8().(bytes) { |
| 440 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => bytes.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]len().(), |
| 441 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(s) => strip_formattingrust-analyzer cargo tabwriter 1.4.1 strip_formatting().(s) |
| 442 | .charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() |
| 443 | .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|c| UnicodeWidthCharrust-analyzer cargo unicode-width 0.2.2 UnicodeWidthChar#::widthrust-analyzer cargo unicode-width 0.2.2 impl#[char][UnicodeWidthChar]width().(c).unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap_or().(0)) |
| 444 | .foldrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/map/impl#[`Map<I, F>`][Iterator]fold().(0, |sum, width| sum rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().width), |
| 445 | } |
| 446 | } |
| 447 | |
| 448 | fn strip_formattingrust-analyzer cargo tabwriter 1.4.1 strip_formatting().<'t>(input: &'t str) -> stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#<'t, str> { |
| 449 | let mut escapes = find_ansi_escapesrust-analyzer cargo tabwriter 1.4.1 find_ansi_escapes().(input).peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(); |
| 450 | if escapes.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 451 | return stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Borrowedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Borrowed#(input); |
| 452 | } |
| 453 | let mut without_escapes = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::with_capacityrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]with_capacity().(input.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().()); |
| 454 | let mut last_end = 0; |
| 455 | for mat in escapes { |
| 456 | without_escapes.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().last_end..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#mat.startrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#start.]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 457 | last_end = mat.endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end.; |
| 458 | } |
| 459 | without_escapes.push_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push_str().(&input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().last_end..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().); |
| 460 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::borrowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/::Cowrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#::Ownedrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc borrow/Cow#Owned#(without_escapes) |
| 461 | } |
| 462 | |
| 463 | fn find_ansi_escapesrust-analyzer cargo tabwriter 1.4.1 find_ansi_escapes().<'t>( |
| 464 | input: &'t str, |
| 465 | ) -> impl Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#Item# = stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::opsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/::Rangerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#<usize>> + 't { |
| 466 | const ESCAPE_PREFIXrust-analyzer cargo tabwriter 1.4.1 ESCAPE_PREFIX.: &str = "\x1B["; |
| 467 | let mut last_end = 0; |
| 468 | stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::from_fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/sources/from_fn/from_fn().(move || { |
| 469 | let start = last_end |
| 470 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().last_end..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..match_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]match_indices().(ESCAPE_PREFIXrust-analyzer cargo tabwriter 1.4.1 ESCAPE_PREFIX.).nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`MatchIndices<'a, P>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..0; |
| 471 | let after_prefix = start rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().+rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().ESCAPE_PREFIXrust-analyzer cargo tabwriter 1.4.1 ESCAPE_PREFIX..lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().(); |
| 472 | let end = after_prefix |
| 473 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().input[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().after_prefix..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/RangeFrom#]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index()..match_indicesrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]match_indices().('m').nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/iter/impl#[`MatchIndices<'a, P>`][Iterator]next().()?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`][Try]branch()..0 |
| 474 | +rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Add<Self>`]add().1; |
| 475 | last_end = end; |
| 476 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(start..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#end) |
| 477 | }) |
| 478 | } |