Debian Codegraph @

src/table.rs

raw symbols SCIP
1 #[cfg(feature = "tty")]
2 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::syncrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/::OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#;
3 use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::{
4 collectionsrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/::HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#,
5 fmtrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc fmt/,
6 iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#,
7 slicerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/::{Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#, IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#},
8 };
9
10 use craterust-analyzer cargo comfy-table 7.2.2 crate/::{
11 cellrust-analyzer cargo comfy-table 7.2.2 cell/::Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#,
12 columnrust-analyzer cargo comfy-table 7.2.2 column/::Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#,
13 rowrust-analyzer cargo comfy-table 7.2.2 row/::Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#,
14 stylerust-analyzer cargo comfy-table 7.2.2 style/::{ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#, ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#, TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#, presetsrust-analyzer cargo comfy-table 7.2.2 style/presets/::ASCII_FULLrust-analyzer cargo comfy-table 7.2.2 style/presets/ASCII_FULL.},
15 utilsrust-analyzer cargo comfy-table 7.2.2 utils/::build_tablerust-analyzer cargo comfy-table 7.2.2 utils/build_table().,
16 };
17
18 /// This is the main interface for building a table.
19 /// Each table consists of [Rows](Row), which in turn contain [Cells](crate::cell::Cell).
20 ///
21 /// There also exists a representation of a [Column].
22 /// Columns are automatically created when adding rows to a table.
23 #[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:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:)]
24 pub struct Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# {
25 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#>,
26 stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#<TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#, char>,
27 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) headerrust-analyzer cargo comfy-table 7.2.2 table/Table#header.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>,
28 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>,
29 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) arrangementrust-analyzer cargo comfy-table 7.2.2 table/Table#arrangement.: ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#,
30 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) delimiterrust-analyzer cargo comfy-table 7.2.2 table/Table#delimiter.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char>,
31 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) truncation_indicatorrust-analyzer cargo comfy-table 7.2.2 table/Table#truncation_indicator.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#,
32 #[cfg(feature = "tty")]
33 no_ttyrust-analyzer cargo comfy-table 7.2.2 table/Table#no_tty.: bool,
34 #[cfg(feature = "tty")]
35 is_tty_cacherust-analyzer cargo comfy-table 7.2.2 table/Table#is_tty_cache.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#<bool>,
36 #[cfg(feature = "tty")]
37 use_stderrrust-analyzer cargo comfy-table 7.2.2 table/Table#use_stderr.: bool,
38 widthrust-analyzer cargo comfy-table 7.2.2 table/Table#width.: Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16>,
39 #[cfg(feature = "tty")]
40 enforce_stylingrust-analyzer cargo comfy-table 7.2.2 table/Table#enforce_styling.: bool,
41 /// Define whether everything in a cells should be styled, including whitespaces
42 /// or whether only the text should be styled.
43 #[cfg(feature = "tty")]
44 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) style_text_onlyrust-analyzer cargo comfy-table 7.2.2 table/Table#style_text_only.: bool,
45 }
46
47 impl 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 Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# {
48 fn fmtrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table][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# {
49 writerust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/write!!(f, "{}", self.linesrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]lines().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>().joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n"))
50 }
51 }
52
53 impl Defaultrust-analyzer cargo core https://github.com/rust-lang/rust/library/core default/Default# for Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# {
54 fn defaultrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table][Default]default().() -> Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table][Default] {
55 Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table][Default]::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().()
56 }
57 }
58
59 impl Tablerust-analyzer cargo comfy-table 7.2.2 table/Table# {
60 /// Create a new table with default ASCII styling.
61 pub fn newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().() -> Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
62 let mut table = Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
63 columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(),
64 headerrust-analyzer cargo comfy-table 7.2.2 table/Table#header.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
65 rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows.: Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(),
66 arrangementrust-analyzer cargo comfy-table 7.2.2 table/Table#arrangement.: ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#::Disabledrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#Disabled#,
67 delimiterrust-analyzer cargo comfy-table 7.2.2 table/Table#delimiter.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
68 truncation_indicatorrust-analyzer cargo comfy-table 7.2.2 table/Table#truncation_indicator.: "...".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
69 #[cfg(feature = "tty")]
70 no_ttyrust-analyzer cargo comfy-table 7.2.2 table/Table#no_tty.: false,
71 #[cfg(feature = "tty")]
72 is_tty_cacherust-analyzer cargo comfy-table 7.2.2 table/Table#is_tty_cache.: OnceLockrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/OnceLock#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]new().(),
73 #[cfg(feature = "tty")]
74 use_stderrrust-analyzer cargo comfy-table 7.2.2 table/Table#use_stderr.: false,
75 widthrust-analyzer cargo comfy-table 7.2.2 table/Table#width.: Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
76 stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style.: HashMaprust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/HashMap#::newrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V>`]new().(),
77 #[cfg(feature = "tty")]
78 enforce_stylingrust-analyzer cargo comfy-table 7.2.2 table/Table#enforce_styling.: false,
79 #[cfg(feature = "tty")]
80 style_text_onlyrust-analyzer cargo comfy-table 7.2.2 table/Table#style_text_only.: false,
81 };
82
83 table.load_presetrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]load_preset().(ASCII_FULLrust-analyzer cargo comfy-table 7.2.2 style/presets/ASCII_FULL.);
84
85 table
86 }
87
88 /// This is an alternative `fmt` function, which simply removes any trailing whitespaces.
89 /// Trailing whitespaces often occur, when using tables without a right border.
90 pub fn trim_fmtrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]trim_fmt().(&self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
91 self.linesrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]lines().()
92 .maprust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#map().(|line| line.trim_endrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]trim_end().().to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().())
93 .collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<_>>()
94 .joinrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc slice/impl#[`[T]`]join().("\n")
95 }
96
97 /// This is an alternative to `fmt`, but rather returns an iterator to each line, rather than
98 /// one String separated by newlines.
99 pub fn linesrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]lines().(&self) -> 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# = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> {
100 build_tablerust-analyzer cargo comfy-table 7.2.2 utils/build_table().(self)
101 }
102
103 /// Set the header row of the table. This is usually the title of each column.\
104 /// There'll be no header unless you explicitly set it with this function.
105 ///
106 /// ```
107 /// use comfy_table::{Row, Table};
108 ///
109 /// let mut table = Table::new();
110 /// let header = Row::from(vec!["Header One", "Header Two"]);
111 /// table.set_header(header);
112 /// ```
113 pub fn set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().<T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>>(&mut self, row: T) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
114 let row = row.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
115 self.autogenerate_columnsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]autogenerate_columns().(&row);
116 self.headerrust-analyzer cargo comfy-table 7.2.2 table/Table#header. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row);
117
118 self
119 }
120
121 pub fn headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]header().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#> {
122 self.headerrust-analyzer cargo comfy-table 7.2.2 table/Table#header..as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().()
123 }
124
125 /// Returns the number of currently present columns.
126 ///
127 /// ```
128 /// use comfy_table::Table;
129 ///
130 /// let mut table = Table::new();
131 /// table.set_header(vec!["Col 1", "Col 2", "Col 3"]);
132 ///
133 /// assert_eq!(table.column_count(), 3);
134 /// ```
135 pub fn column_countrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_count().(&mut self) -> usize {
136 self.discover_columnsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]discover_columns().();
137 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
138 }
139
140 /// Add a new row to the table.
141 ///
142 /// ```
143 /// use comfy_table::{Row, Table};
144 ///
145 /// let mut table = Table::new();
146 /// table.add_row(vec!["One", "Two"]);
147 /// ```
148 pub fn add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().<T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>>(&mut self, row: T) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
149 let mut row = row.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
150 self.autogenerate_columnsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]autogenerate_columns().(&row);
151 row.indexrust-analyzer cargo comfy-table 7.2.2 row/Row#index. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
152 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(row);
153
154 self
155 }
156
157 /// Add a new row to the table if the predicate evaluates to `true`.
158 ///
159 /// ```
160 /// use comfy_table::{Row, Table};
161 ///
162 /// let mut table = Table::new();
163 /// table.add_row_if(|index, row| true, vec!["One", "Two"]);
164 /// ```
165 pub fn add_row_ifrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row_if().<P, T>(&mut self, predicate: P, row: T) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]
166 where
167 P: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(usize, &T) -> bool,
168 T: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>,
169 {
170 if predicate(self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), &row) {
171 return self.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(row);
172 }
173
174 self
175 }
176
177 /// Add multiple rows to the table.
178 ///
179 /// ```
180 /// use comfy_table::{Row, Table};
181 ///
182 /// let mut table = Table::new();
183 /// let rows = vec![vec!["One", "Two"], vec!["Three", "Four"]];
184 /// table.add_rows(rows);
185 /// ```
186 pub fn add_rowsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_rows().<I>(&mut self, rows: I) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]
187 where
188 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#,
189 I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>,
190 {
191 for row in rows.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().() {
192 let mut row = row.intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#into().();
193 self.autogenerate_columnsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]autogenerate_columns().(&row);
194 row.indexrust-analyzer cargo comfy-table 7.2.2 row/Row#index. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().());
195 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(row);
196 }
197
198 self
199 }
200
201 /// Add multiple rows to the table if the predicate evaluates to `true`.
202 ///
203 /// ```
204 /// use comfy_table::{Row, Table};
205 ///
206 /// let mut table = Table::new();
207 /// let rows = vec![vec!["One", "Two"], vec!["Three", "Four"]];
208 /// table.add_rows_if(|index, rows| true, rows);
209 /// ```
210 pub fn add_rows_ifrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_rows_if().<P, I>(&mut self, predicate: P, rows: I) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]
211 where
212 P: Fnrust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/Fn#(usize, &I) -> bool,
213 I: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#,
214 I::Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item#: Intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/Into#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>,
215 {
216 if predicate(self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), &rows) {
217 return self.add_rowsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_rows().(rows);
218 }
219
220 self
221 }
222
223 /// Returns the number of currently present rows.
224 ///
225 /// ```
226 /// use comfy_table::Table;
227 ///
228 /// let mut table = Table::new();
229 /// table.add_row(vec!["One", "Two"]);
230 ///
231 /// assert_eq!(table.row_count(), 1);
232 /// ```
233 pub fn row_countrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_count().(&self) -> usize {
234 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()
235 }
236
237 /// Returns if the table is empty (contains no data rows).
238 ///
239 /// ```
240 /// use comfy_table::Table;
241 ///
242 /// let mut table = Table::new();
243 /// assert!(table.is_empty());
244 ///
245 /// table.add_row(vec!["One", "Two"]);
246 /// assert!(!table.is_empty());
247 /// ```
248 pub fn is_emptyrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]is_empty().(&self) -> bool {
249 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..is_emptyrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]is_empty().()
250 }
251
252 /// Enforce a max width that should be used in combination with [dynamic content
253 /// arrangement](ContentArrangement::Dynamic).\ This is usually not necessary, if you plan
254 /// to output your table to a tty, since the terminal width can be automatically determined.
255 pub fn set_widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_width().(&mut self, width: u16) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
256 self.widthrust-analyzer cargo comfy-table 7.2.2 table/Table#width. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(width);
257
258 self
259 }
260
261 /// Get the expected width of the table.
262 ///
263 /// This will be `Some(width)`, if the terminal width can be detected or if the table width is
264 /// set via [set_width](Table::set_width).
265 ///
266 /// If neither is not possible, `None` will be returned.\
267 /// This implies that both the [Dynamic](ContentArrangement::Dynamic) mode and the
268 /// [Percentage](crate::style::Width::Percentage) constraint won't work.
269 #[cfg(feature = "tty")]
270 pub fn widthrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]width().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16> {
271 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(width) = self.widthrust-analyzer cargo comfy-table 7.2.2 table/Table#width. {
272 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(width)
273 } else if self.is_ttyrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]is_tty().() {
274 if let Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#((width, _)) = crosstermrust-analyzer cargo crossterm 0.29.0 crate/::terminalrust-analyzer cargo crossterm 0.29.0 terminal/::sizerust-analyzer cargo crossterm 0.29.0 terminal/size().() {
275 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(width)
276 } else {
277 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
278 }
279 } else {
280 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
281 }
282 }
283
284 #[cfg(not(feature = "tty"))]
285 pub fn width(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<u16> {
286 selfrust-analyzer cargo comfy-table 7.2.2 table/.width
287 }
288
289 /// Specify how Comfy Table should arrange the content in your table.
290 ///
291 /// ```
292 /// use comfy_table::{ContentArrangement, Table};
293 ///
294 /// let mut table = Table::new();
295 /// table.set_content_arrangement(ContentArrangement::Dynamic);
296 /// ```
297 pub fn set_content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_content_arrangement().(&mut self, arrangement: ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement#) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
298 self.arrangementrust-analyzer cargo comfy-table 7.2.2 table/Table#arrangement. = arrangement;
299
300 self
301 }
302
303 /// Get the current content arrangement of the table.
304 pub fn content_arrangementrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]content_arrangement().(&self) -> ContentArrangementrust-analyzer cargo comfy-table 7.2.2 style/table/ContentArrangement# {
305 self.arrangementrust-analyzer cargo comfy-table 7.2.2 table/Table#arrangement..clonerust-analyzer cargo comfy-table 7.2.2 style/table/impl#[ContentArrangement][Clone]clone().()
306 }
307
308 /// Set the delimiter used to split text in all cells.
309 ///
310 /// A custom delimiter on a cell in will overwrite the column's delimiter.\
311 /// Normal text uses spaces (` `) as delimiters. This is necessary to help comfy-table
312 /// understand the concept of _words_.
313 pub fn set_delimiterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_delimiter().(&mut self, delimiter: char) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
314 self.delimiterrust-analyzer cargo comfy-table 7.2.2 table/Table#delimiter. = Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(delimiter);
315
316 self
317 }
318
319 /// Set the truncation indicator for cells that are too long to be displayed.
320 ///
321 /// Set it to "…" for example to use an ellipsis that only takes up one character.
322 pub fn set_truncation_indicatorrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_truncation_indicator().(&mut self, indicator: &str) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
323 self.truncation_indicatorrust-analyzer cargo comfy-table 7.2.2 table/Table#truncation_indicator. = indicator.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().();
324
325 self
326 }
327
328 /// In case you are sure you don't want export tables to a tty or you experience
329 /// problems with tty specific code, you can enforce a non_tty mode.
330 ///
331 /// This disables:
332 ///
333 /// - width lookup from the current tty
334 /// - Styling and attributes on cells (unless you use [Table::enforce_styling])
335 ///
336 /// If you use the [dynamic content arrangement](ContentArrangement::Dynamic),
337 /// you need to set the width of your desired table manually with [set_width](Table::set_width).
338 #[cfg(feature = "tty")]
339 pub fn force_no_ttyrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]force_no_tty().(&mut self) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
340 self.no_ttyrust-analyzer cargo comfy-table 7.2.2 table/Table#no_tty. = true;
341
342 self
343 }
344
345 /// Use this function to check whether `stderr` is a tty.
346 ///
347 /// The default is `stdout`.
348 #[cfg(feature = "tty")]
349 pub fn use_stderrrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]use_stderr().(&mut self) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
350 self.use_stderrrust-analyzer cargo comfy-table 7.2.2 table/Table#use_stderr. = true;
351
352 self
353 }
354
355 /// Returns whether the table will be handled as if it's printed to a tty.
356 ///
357 /// By default, comfy-table looks at `stdout` and checks whether it's a tty.
358 /// This behavior can be changed via [Table::force_no_tty] and [Table::use_stderr].
359 #[cfg(feature = "tty")]
360 pub fn is_ttyrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]is_tty().(&self) -> bool {
361 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/::IsTerminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/IsTerminal#;
362
363 if self.no_ttyrust-analyzer cargo comfy-table 7.2.2 table/Table#no_tty. {
364 return false;
365 }
366
367 *rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().self.is_tty_cacherust-analyzer cargo comfy-table 7.2.2 table/Table#is_tty_cache..get_or_initrust-analyzer cargo std https://github.com/rust-lang/rust/library/std sync/once_lock/impl#[`OnceLock<T>`]get_or_init().(|| {
368 if self.use_stderrrust-analyzer cargo comfy-table 7.2.2 table/Table#use_stderr. {
369 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/::stderrrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stderr().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stderr][IsTerminal]is_terminal().()
370 } else {
371 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/::stdoutrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/stdout().().is_terminalrust-analyzer cargo std https://github.com/rust-lang/rust/library/std io/stdio/impl#[Stdout][IsTerminal]is_terminal().()
372 }
373 })
374 }
375
376 /// Enforce terminal styling.
377 ///
378 /// Only useful if you forcefully disabled tty, but still want those fancy terminal styles.
379 ///
380 /// ```
381 /// use comfy_table::Table;
382 ///
383 /// let mut table = Table::new();
384 /// table.force_no_tty().enforce_styling();
385 /// ```
386 #[cfg(feature = "tty")]
387 pub fn enforce_stylingrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]enforce_styling().(&mut self) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
388 self.enforce_stylingrust-analyzer cargo comfy-table 7.2.2 table/Table#enforce_styling. = true;
389
390 self
391 }
392
393 /// Returns whether the content of this table should be styled with the current settings and
394 /// environment.
395 #[cfg(feature = "tty")]
396 pub fn should_stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]should_style().(&self) -> bool {
397 if self.enforce_stylingrust-analyzer cargo comfy-table 7.2.2 table/Table#enforce_styling. {
398 return true;
399 }
400 self.is_ttyrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]is_tty().()
401 }
402
403 /// By default, the whole content of a cells will be styled.
404 /// Calling this function disables this behavior for all cells, resulting in
405 /// only the text of cells being styled.
406 #[cfg(feature = "tty")]
407 pub fn style_text_onlyrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]style_text_only().(&mut self) {
408 self.style_text_onlyrust-analyzer cargo comfy-table 7.2.2 table/Table#style_text_only. = true;
409 }
410
411 /// Convenience method to set a [ColumnConstraint] for all columns at once.
412 /// Constraints are used to influence the way the columns will be arranged.
413 /// Check out their docs for more information.
414 ///
415 /// **Attention:**
416 /// This function should be called after at least one row (or the headers) has been added to the
417 /// table. Before that, the columns won't initialized.
418 ///
419 /// If more constraints are passed than there are columns, any superfluous constraints will be
420 /// ignored. ```
421 /// use comfy_table::{CellAlignment, ColumnConstraint::*, ContentArrangement, Table, Width::*};
422 ///
423 /// let mut table = Table::new();
424 /// table
425 /// .add_row(&vec!["one", "two", "three"])
426 /// .set_content_arrangement(ContentArrangement::Dynamic)
427 /// .set_constraints(vec![UpperBoundary(Fixed(15)), LowerBoundary(Fixed(20))]);
428 /// ```
429 pub fn set_constraintsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_constraints().<T: IntoIteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#<Itemrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#Item# = ColumnConstraintrust-analyzer cargo comfy-table 7.2.2 style/column/ColumnConstraint#>>(
430 &mut self,
431 constraints: T,
432 ) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
433 let mut constraints = constraints.into_iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/collect/IntoIterator#into_iter().();
434 for column in self.column_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter_mut().() {
435 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(constraint) = constraints.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#next().() {
436 column.set_constraintrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]set_constraint().(constraint);
437 } else {
438 break;
439 }
440 }
441
442 self
443 }
444
445 /// This function creates a TableStyle from a given preset string.\
446 /// Preset strings can be found in `styling::presets::*`.
447 ///
448 /// You can also write your own preset strings and use them with this function.
449 /// There's the convenience method [Table::current_style_as_preset], which prints you a preset
450 /// string from your current style configuration. \
451 /// The function expects the to-be-drawn characters to be in the same order as in the
452 /// [TableComponent] enum.
453 ///
454 /// If the string isn't long enough, the default [ASCII_FULL] style will be used for all
455 /// remaining components.
456 ///
457 /// If the string is too long, remaining charaacters will be simply ignored.
458 pub fn load_presetrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]load_preset().(&mut self, preset: &str) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
459 let mut components = TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#::iterrust-analyzer cargo comfy-table 7.2.2 style/table/impl#[TableComponent]iter().();
460
461 for character in preset.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() {
462 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(component) = components.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`IntoIter<T, N>`][Iterator]next().() {
463 // White spaces mean "don't draw this" in presets
464 // If we want to override the default preset, we need to remove
465 // this component from the HashMap in case we find a whitespace.
466 if character rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ' {
467 self.remove_stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]remove_style().(component);
468 continue;
469 }
470
471 self.set_stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_style().(component, character);
472 } else {
473 break;
474 }
475 }
476
477 self
478 }
479
480 /// Returns the current style as a preset string.
481 ///
482 /// A pure convenience method, so you're not force to fiddle with those preset strings yourself.
483 ///
484 /// ```
485 /// use comfy_table::{Table, presets::UTF8_FULL};
486 ///
487 /// let mut table = Table::new();
488 /// table.load_preset(UTF8_FULL);
489 ///
490 /// assert_eq!(UTF8_FULL, table.current_style_as_preset())
491 /// ```
492 pub fn current_style_as_presetrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]current_style_as_preset().(&mut self) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
493 let components = TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#::iterrust-analyzer cargo comfy-table 7.2.2 style/table/impl#[TableComponent]iter().();
494 let mut preset_string = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().();
495
496 for component in components {
497 match self.stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]style().(component) {
498 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => preset_string.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(' '),
499 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(character) => preset_string.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(character),
500 }
501 }
502
503 preset_string
504 }
505
506 /// Modify a preset with a modifier string from [modifiers](crate::style::modifiers).
507 ///
508 /// For instance, the [UTF8_ROUND_CORNERS](crate::style::modifiers::UTF8_ROUND_CORNERS) modifies
509 /// all corners to be round UTF8 box corners.
510 ///
511 /// ```
512 /// use comfy_table::{Table, modifiers::UTF8_ROUND_CORNERS, presets::UTF8_FULL};
513 ///
514 /// let mut table = Table::new();
515 /// table.load_preset(UTF8_FULL);
516 /// table.apply_modifier(UTF8_ROUND_CORNERS);
517 /// ```
518 pub fn apply_modifierrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]apply_modifier().(&mut self, modifier: &str) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
519 let mut components = TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#::iterrust-analyzer cargo comfy-table 7.2.2 style/table/impl#[TableComponent]iter().();
520
521 for character in modifier.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() {
522 // Skip spaces while applying modifiers.
523 if character rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().' ' {
524 components.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`IntoIter<T, N>`][Iterator]next().();
525 continue;
526 }
527 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(component) = components.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core array/iter/impl#[`IntoIter<T, N>`][Iterator]next().() {
528 self.set_stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_style().(component, character);
529 } else {
530 break;
531 }
532 }
533
534 self
535 }
536
537 /// Define the char that will be used to draw a specific component.\
538 /// Look at [TableComponent] to see all stylable components
539 ///
540 /// If `None` is supplied, the element won't be displayed.\
541 /// In case of a e.g. *BorderIntersection a whitespace will be used as placeholder,
542 /// unless related borders and and corners are set to `None` as well.
543 ///
544 /// For example, if `TopBorderIntersections` is `None` the first row would look like this:
545 ///
546 /// ```text
547 /// +------ ------+
548 /// | this | test |
549 /// ```
550 ///
551 /// If in addition `TopLeftCorner`,`TopBorder` and `TopRightCorner` would be `None` as well,
552 /// the first line wouldn't be displayed at all.
553 ///
554 /// ```
555 /// use comfy_table::{Table, TableComponent::*, presets::UTF8_FULL};
556 ///
557 /// let mut table = Table::new();
558 /// // Load the UTF8_FULL preset
559 /// table.load_preset(UTF8_FULL);
560 /// // Set all outer corners to round UTF8 corners
561 /// // This is basically the same as the UTF8_ROUND_CORNERS modifier
562 /// table.set_style(TopLeftCorner, 'â•­');
563 /// table.set_style(TopRightCorner, 'â•®');
564 /// table.set_style(BottomLeftCorner, 'â•°');
565 /// table.set_style(BottomRightCorner, '╯');
566 /// ```
567 pub fn set_stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_style().(&mut self, component: TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#, character: char) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
568 self.stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style..insertrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]insert().(component, character);
569
570 self
571 }
572
573 /// Get a copy of the char that's currently used for drawing this component.
574 /// ```
575 /// use comfy_table::{Table, TableComponent::*};
576 ///
577 /// let mut table = Table::new();
578 /// assert_eq!(table.style(TopLeftCorner), Some('+'));
579 /// ```
580 pub fn stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]style().(&mut self, component: TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<char> {
581 self.stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&component).copiedrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<&T>`]copied().()
582 }
583
584 /// Remove the style for a specific component of the table.\
585 /// By default, a space will be used as a placeholder instead.\
586 /// Though, if for instance all components of the left border are removed, the left border won't
587 /// be displayed.
588 pub fn remove_stylerust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]remove_style().(&mut self, component: TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#) -> &mut Selfrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table] {
589 self.stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style..removerust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]remove().(&component);
590
591 self
592 }
593
594 /// Get a reference to a specific column.
595 pub fn columnrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column().(&self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#> {
596 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(index)
597 }
598
599 /// Get a mutable reference to a specific column.
600 pub fn column_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_mut().(&mut self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#> {
601 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(index)
602 }
603
604 /// Iterator over all columns
605 pub fn column_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter().(&self) -> Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'_, Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#> {
606 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
607 }
608
609 /// Get a mutable iterator over all columns.
610 ///
611 /// ```
612 /// use comfy_table::{ColumnConstraint::*, Table, Width::*};
613 ///
614 /// let mut table = Table::new();
615 /// table.add_row(&vec!["First", "Second", "Third"]);
616 ///
617 /// // Add a ColumnConstraint to each column (left->right)
618 /// // first -> min width of 10
619 /// // second -> max width of 8
620 /// // third -> fixed width of 10
621 /// let constraints = vec![
622 /// LowerBoundary(Fixed(10)),
623 /// UpperBoundary(Fixed(8)),
624 /// Absolute(Fixed(10)),
625 /// ];
626 ///
627 /// // Add the constraints to their respective column
628 /// for (column_index, column) in table.column_iter_mut().enumerate() {
629 /// let constraint = constraints.get(column_index).unwrap();
630 /// column.set_constraint(*constraint);
631 /// }
632 /// ```
633 pub fn column_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_iter_mut().(&mut self) -> IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#<'_, Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#> {
634 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()
635 }
636
637 /// Get a mutable iterator over cells of a column.
638 /// The iterator returns a nested `Option<Option<Cell>>`, since there might be
639 /// rows that are missing this specific Cell.
640 ///
641 /// ```
642 /// use comfy_table::Table;
643 /// let mut table = Table::new();
644 /// table.add_row(&vec!["First", "Second"]);
645 /// table.add_row(&vec!["Third"]);
646 /// table.add_row(&vec!["Fourth", "Fifth"]);
647 ///
648 /// // Create an iterator over the second column
649 /// let mut cell_iter = table.column_cells_iter(1);
650 /// assert_eq!(cell_iter.next().unwrap().unwrap().content(), "Second");
651 /// assert!(cell_iter.next().unwrap().is_none());
652 /// assert_eq!(cell_iter.next().unwrap().unwrap().content(), "Fifth");
653 /// assert!(cell_iter.next().is_none());
654 /// ```
655 pub fn column_cells_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_cells_iter().(&self, column_index: usize) -> ColumnCellIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#<'_> {
656 ColumnCellIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter# {
657 rowsrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#rows.: &self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows.,
658 column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#column_index.,
659 row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#row_index.: 0,
660 }
661 }
662
663 /// Get a mutable iterator over cells of a column, including the header cell.
664 /// The header cell will be the very first cell returned.
665 /// The iterator returns a nested `Option<Option<Cell>>`, since there might be
666 /// rows that are missing this specific Cell.
667 ///
668 /// ```
669 /// use comfy_table::Table;
670 /// let mut table = Table::new();
671 /// table.set_header(&vec!["A", "B"]);
672 /// table.add_row(&vec!["First", "Second"]);
673 /// table.add_row(&vec!["Third"]);
674 /// table.add_row(&vec!["Fourth", "Fifth"]);
675 ///
676 /// // Create an iterator over the second column
677 /// let mut cell_iter = table.column_cells_with_header_iter(1);
678 /// assert_eq!(cell_iter.next().unwrap().unwrap().content(), "B");
679 /// assert_eq!(cell_iter.next().unwrap().unwrap().content(), "Second");
680 /// assert!(cell_iter.next().unwrap().is_none());
681 /// assert_eq!(cell_iter.next().unwrap().unwrap().content(), "Fifth");
682 /// assert!(cell_iter.next().is_none());
683 /// ```
684 pub fn column_cells_with_header_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_cells_with_header_iter().(
685 &self,
686 column_index: usize,
687 ) -> ColumnCellsWithHeaderIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#<'_> {
688 ColumnCellsWithHeaderIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter# {
689 header_checkedrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header_checked.: false,
690 headerrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header.: &self.headerrust-analyzer cargo comfy-table 7.2.2 table/Table#header.,
691 rowsrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#rows.: &self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows.,
692 column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#column_index.,
693 row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#row_index.: 0,
694 }
695 }
696
697 /// Reference to a specific row
698 pub fn rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row().(&self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#> {
699 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(index)
700 }
701
702 /// Mutable reference to a specific row
703 pub fn row_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_mut().(&mut self, index: usize) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&mut Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#> {
704 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..get_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get_mut().(index)
705 }
706
707 /// Iterator over all rows
708 pub fn row_iterrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_iter().(&self) -> Iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/Iter#<'_, Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#> {
709 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().()
710 }
711
712 /// Get a mutable iterator over all rows.
713 ///
714 /// ```
715 /// use comfy_table::Table;
716 /// let mut table = Table::new();
717 /// table.add_row(&vec!["First", "Second", "Third"]);
718 ///
719 /// // Add the constraints to their respective row
720 /// for row in table.row_iter_mut() {
721 /// row.max_height(5);
722 /// }
723 /// assert!(table.row_iter_mut().len() == 1);
724 /// ```
725 pub fn row_iter_mutrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]row_iter_mut().(&mut self) -> IterMutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/iter/IterMut#<'_, Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#> {
726 self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..iter_mutrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter_mut().()
727 }
728
729 /// Return a vector representing the maximum amount of characters in any line of this column.\
730 ///
731 /// **Attention** This scans the whole current content of the table.
732 pub fn column_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_max_content_widths().(&self) -> Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<u16> {
733 fn set_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/set_max_content_widths().(max_widths: &mut [u16], row: &Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#) {
734 // Get the max width for each cell of the row
735 let row_max_widths = row.max_content_widthsrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]max_content_widths().();
736 for (index, width) in row_max_widths.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().() {
737 let mut width = (*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().width).try_intorust-analyzer cargo core https://github.com/rust-lang/rust/library/core convert/impl#[T][`TryInto<U>`]try_into().().unwrap_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`]unwrap_or().(u16::MAXrust-analyzer cargo core https://github.com/rust-lang/rust/library/core num/impl#[u16]MAX.);
738 // A column's content is at least 1 char wide.
739 width = 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/::maxrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/max().(1, width);
740
741 // Set a new max, if the current cell is the longest for that column.
742 let current_max = max_widths[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/Index#index().;
743 if current_max rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().<rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[u16][`PartialOrd<Self>`]lt().width {
744 max_widths[rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut().index]rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/index/IndexMut#index_mut(). = width;
745 }
746 }
747 }
748 // The vector that'll contain the max widths per column.
749 let mut max_widths = vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![0; self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().()];
750
751 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header) = &self.headerrust-analyzer cargo comfy-table 7.2.2 table/Table#header. {
752 set_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/set_max_content_widths().(&mut max_widths, header);
753 }
754 // Iterate through all rows of the table.
755 for row in self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
756 set_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/set_max_content_widths().(&mut max_widths, row);
757 }
758
759 max_widths
760 }
761
762 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) fn style_or_defaultrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]style_or_default().(&self, component: TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#) -> Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String# {
763 match self.stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style..getrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]get().(&component) {
764 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => " ".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
765 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(character) => character.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(),
766 }
767 }
768
769 pub(craterust-analyzer cargo comfy-table 7.2.2 crate/) fn style_existsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]style_exists().(&self, component: TableComponentrust-analyzer cargo comfy-table 7.2.2 style/table/TableComponent#) -> bool {
770 self.stylerust-analyzer cargo comfy-table 7.2.2 table/Table#style..contains_keyrust-analyzer cargo std https://github.com/rust-lang/rust/library/std collections/hash/map/impl#[`HashMap<K, V, S, A>`]contains_key().(&component)
771 }
772
773 /// Autogenerate new columns, if a row is added with more cells than existing columns.
774 fn autogenerate_columnsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]autogenerate_columns().(&mut self, row: &Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#) {
775 if row.cell_countrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]cell_count().() 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().self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
776 for index in self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..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#row.cell_countrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]cell_count().() {
777 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#::newrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]new().(index));
778 }
779 }
780 }
781
782 /// Calling this might be necessary if you add new cells to rows that're already added to the
783 /// table.
784 ///
785 /// If more cells than're currently know to the table are added to that row,
786 /// the table cannot know about these, since new [Column]s are only
787 /// automatically detected when a new row is added.
788 ///
789 /// To make sure everything works as expected, just call this function if you're adding cells
790 /// to rows that're already added to the table.
791 pub fn discover_columnsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]discover_columns().(&mut self) {
792 for row in self.rowsrust-analyzer cargo comfy-table 7.2.2 table/Table#rows..iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().() {
793 if row.cell_countrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]cell_count().() 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().self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().() {
794 for index in self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..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#row.cell_countrust-analyzer cargo comfy-table 7.2.2 row/impl#[Row]cell_count().() {
795 self.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Columnrust-analyzer cargo comfy-table 7.2.2 column/Column#::newrust-analyzer cargo comfy-table 7.2.2 column/impl#[Column]new().(index));
796 }
797 }
798 }
799 }
800 }
801
802 /// An iterator over cells of a specific column.
803 /// A dedicated struct is necessary, as data is usually handled by rows and thereby stored in
804 /// `Table::rows`. This type is returned by [Table::column_cells_iter].
805 pub struct ColumnCellIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#<'a> {
806 rowsrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#rows.: &'a [Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#],
807 column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#column_index.: usize,
808 row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#row_index.: usize,
809 }
810
811 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ColumnCellIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#<'a> {
812 type Itemrust-analyzer cargo comfy-table 7.2.2 table/impl#[`ColumnCellIter<'a>`][Iterator]Item# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#>;
813 fn nextrust-analyzer cargo comfy-table 7.2.2 table/impl#[`ColumnCellIter<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#>> {
814 // Check if there's a next row
815 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row) = self.rowsrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#rows..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#row_index.) {
816 self.row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#row_index. 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;
817
818 // Return the cell (if it exists).
819 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row.cellsrust-analyzer cargo comfy-table 7.2.2 row/Row#cells..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellIter#column_index.));
820 }
821
822 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
823 }
824 }
825
826 /// An iterator over cells of a specific column.
827 /// A dedicated struct is necessary, as data is usually handled by rows and thereby stored in
828 /// `Table::rows`. This type is returned by [Table::column_cells_iter].
829 pub struct ColumnCellsWithHeaderIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#<'a> {
830 header_checkedrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header_checked.: bool,
831 headerrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header.: &'a Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#>,
832 rowsrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#rows.: &'a [Rowrust-analyzer cargo comfy-table 7.2.2 row/Row#],
833 column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#column_index.: usize,
834 row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#row_index.: usize,
835 }
836
837 impl<'a> Iteratorrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator# for ColumnCellsWithHeaderIterrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#<'a> {
838 type Itemrust-analyzer cargo comfy-table 7.2.2 table/impl#[`ColumnCellsWithHeaderIter<'a>`][Iterator]Item# = Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#>;
839 fn nextrust-analyzer cargo comfy-table 7.2.2 table/impl#[`ColumnCellsWithHeaderIter<'a>`][Iterator]next().(&mut self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&'a Cellrust-analyzer cargo comfy-table 7.2.2 cell/Cell#>> {
840 // Get the header as the first cell
841 if !rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().self.header_checkedrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header_checked. {
842 self.header_checkedrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header_checked. = true;
843
844 return match self.headerrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#header. {
845 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header) => {
846 // Return the cell (if it exists).
847 Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(header.cellsrust-analyzer cargo comfy-table 7.2.2 row/Row#cells..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#column_index.))
848 }
849 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#),
850 };
851 }
852
853 // Check if there's a next row
854 if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row) = self.rowsrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#rows..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#row_index.) {
855 self.row_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#row_index. 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;
856
857 // Return the cell (if it exists).
858 return Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(row.cellsrust-analyzer cargo comfy-table 7.2.2 row/Row#cells..getrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]get().(self.column_indexrust-analyzer cargo comfy-table 7.2.2 table/ColumnCellsWithHeaderIter#column_index.));
859 }
860
861 Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#
862 }
863 }
864
865 #[cfg(test)]
866 mod testsrust-analyzer cargo comfy-table 7.2.2 table/tests/ {
867 use superrust-analyzer cargo comfy-table 7.2.2 table/::*;
868
869 #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:]
870 fn test_column_generationrust-analyzer cargo comfy-table 7.2.2 table/tests/test_column_generation().() {
871 let mut table = Tablerust-analyzer cargo comfy-table 7.2.2 table/Table#::newrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]new().();
872 table.set_headerrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]set_header().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["thr", "four", "fivef"]);
873
874 // When adding a new row, columns are automatically generated
875 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.columnsrust-analyzer cargo comfy-table 7.2.2 table/Table#columns..lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]len().(), 3);
876 // The max content width is also correctly set for each column
877 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.column_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_max_content_widths().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![3, 4, 5]);
878
879 // When adding a new row, the max content width is updated accordingly
880 table.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["four", "fivef", "very long text with 23"]);
881 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.column_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_max_content_widths().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![4, 5, 22]);
882
883 // Now add a row that has column lines. The max content width shouldn't change
884 table.add_rowrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]add_row().(vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!!["", "", "shorter"]);
885 assert_eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/assert_eq!!(table.column_max_content_widthsrust-analyzer cargo comfy-table 7.2.2 table/impl#[Table]column_max_content_widths().(), vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/vec!![4, 5, 22]);
886
887 printlnrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/println!!("{table}");
888 }
889 }