From b615e03beb20cb836fe643b57291657b9c2845d8 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 9 Mar 2023 01:45:05 -0500 Subject: stop implementing Default for Cell --- src/cell.rs | 10 +++++++++- src/grid.rs | 6 +++--- src/row.rs | 4 ++-- 3 files changed, 14 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/cell.rs b/src/cell.rs index 240ddf9..b7ddd26 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -3,7 +3,7 @@ use unicode_width::UnicodeWidthChar as _; const CODEPOINTS_IN_CELL: usize = 6; /// Represents a single terminal cell. -#[derive(Clone, Debug, Default, Eq)] +#[derive(Clone, Debug, Eq)] pub struct Cell { contents: [char; CODEPOINTS_IN_CELL], len: u8, @@ -25,6 +25,14 @@ impl PartialEq for Cell { } impl Cell { + pub(crate) fn new() -> Self { + Self { + contents: Default::default(), + len: 0, + attrs: crate::attrs::Attrs::default(), + } + } + #[inline] fn len(&self) -> usize { usize::from(self.len & 0x0f) diff --git a/src/grid.rs b/src/grid.rs index dee4e10..a9ecfff 100644 --- a/src/grid.rs +++ b/src/grid.rs @@ -76,7 +76,7 @@ impl Grid { self.size = size; for row in &mut self.rows { - row.resize(size.cols, crate::Cell::default()); + row.resize(size.cols, crate::Cell::new()); } self.rows.resize(usize::from(size.rows), self.new_row()); @@ -496,7 +496,7 @@ impl Grid { if wide { row.get_mut(pos.col).unwrap().set_wide_continuation(false); } - row.insert(pos.col, crate::Cell::default()); + row.insert(pos.col, crate::Cell::new()); if wide { row.get_mut(pos.col).unwrap().set_wide_continuation(true); } @@ -511,7 +511,7 @@ impl Grid { for _ in 0..(count.min(size.cols - pos.col)) { row.remove(pos.col); } - row.resize(size.cols, crate::Cell::default()); + row.resize(size.cols, crate::Cell::new()); } pub fn erase_cells(&mut self, count: u16, attrs: crate::attrs::Attrs) { diff --git a/src/row.rs b/src/row.rs index def12f6..b52146c 100644 --- a/src/row.rs +++ b/src/row.rs @@ -9,7 +9,7 @@ pub struct Row { impl Row { pub fn new(cols: u16) -> Self { Self { - cells: vec![crate::Cell::default(); usize::from(cols)], + cells: vec![crate::Cell::new(); usize::from(cols)], wrapped: false, } } @@ -145,7 +145,7 @@ impl Row { prev_attrs: Option, ) -> (crate::grid::Pos, crate::attrs::Attrs) { let mut prev_was_wide = false; - let default_cell = crate::Cell::default(); + let default_cell = crate::Cell::new(); let mut prev_pos = prev_pos.unwrap_or_else(|| { if wrapping { -- cgit v1.2.3-54-g00ecf