aboutsummaryrefslogtreecommitdiffstats
path: root/src/row.rs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2021-12-14 03:49:13 -0500
committerJesse Luehrs <doy@tozt.net>2021-12-14 04:05:54 -0500
commit2083eae2c5b480ccad672fb2fbb1b2bb5774a606 (patch)
tree9db649b8f73a35d23839f1e189d7e1599306193a /src/row.rs
parent160942c40cbeb7503147c0895217644161fcc84b (diff)
downloadvt100-rust-2083eae2c5b480ccad672fb2fbb1b2bb5774a606.tar.gz
vt100-rust-2083eae2c5b480ccad672fb2fbb1b2bb5774a606.zip
replace all uses of unwrap(), expect(), and indexing with unreachable!()
and also document why they are unreachable
Diffstat (limited to 'src/row.rs')
-rw-r--r--src/row.rs23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/row.rs b/src/row.rs
index 4b0b76e..64b981b 100644
--- a/src/row.rs
+++ b/src/row.rs
@@ -15,7 +15,11 @@ impl Row {
}
fn cols(&self) -> u16 {
- self.cells.len().try_into().unwrap()
+ self.cells
+ .len()
+ .try_into()
+ // we limit the number of cols to a u16 (see Size)
+ .unwrap_or_else(|_| unreachable!())
}
pub fn clear(&mut self, attrs: crate::attrs::Attrs) {
@@ -113,7 +117,8 @@ impl Row {
}
prev_was_wide = cell.is_wide();
- let col: u16 = col.try_into().unwrap();
+ // we limit the number of cols to a u16 (see Size)
+ let col: u16 = col.try_into().unwrap_or_else(|_| unreachable!());
if cell.has_contents() {
for _ in 0..(col - prev_col) {
contents.push(' ');
@@ -180,10 +185,9 @@ impl Row {
}
prev_was_wide = cell.is_wide();
- let pos = crate::grid::Pos {
- row,
- col: col.try_into().unwrap(),
- };
+ // we limit the number of cols to a u16 (see Size)
+ let col: u16 = col.try_into().unwrap_or_else(|_| unreachable!());
+ let pos = crate::grid::Pos { row, col };
if let Some((prev_col, attrs)) = erase {
if cell.has_contents() || cell.attrs() != attrs {
@@ -338,10 +342,9 @@ impl Row {
}
prev_was_wide = cell.is_wide();
- let pos = crate::grid::Pos {
- row,
- col: col.try_into().unwrap(),
- };
+ // we limit the number of cols to a u16 (see Size)
+ let col: u16 = col.try_into().unwrap_or_else(|_| unreachable!());
+ let pos = crate::grid::Pos { row, col };
if let Some((prev_col, attrs)) = erase {
if cell.has_contents() || cell.attrs() != attrs {