From 43a3cdcee50dd13c49daf57badb85709d85287f6 Mon Sep 17 00:00:00 2001 From: xanonid Date: Wed, 24 Oct 2018 09:23:02 +0200 Subject: Improve code style (suggestion by clippy) - usize never < 0 - convert transmute to casts - simplify condition --- src/cell.rs | 2 +- src/lib.rs | 3 +-- src/row.rs | 2 +- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/cell.rs b/src/cell.rs index bc25cec..f27b1bd 100644 --- a/src/cell.rs +++ b/src/cell.rs @@ -190,7 +190,7 @@ impl Cell { /// Set horizontal span for this cell (must be > 0) pub fn set_hspan(&mut self, hspan: usize) { - self.hspan = if hspan <= 0 {1} else {hspan}; + self.hspan = if hspan == 0 {1} else {hspan}; } /// Get horizontal span of this cell (> 0) diff --git a/src/lib.rs b/src/lib.rs index 65f8b0c..0674793 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -15,7 +15,6 @@ use std::fmt; use std::iter::{FromIterator, IntoIterator}; use std::slice::{Iter, IterMut}; use std::ops::{Index, IndexMut}; -use std::mem::transmute; pub use term::{Attr, color}; pub(crate) use term::{Terminal, stdout}; @@ -502,7 +501,7 @@ impl<'a> AsRef> for Table { // All this is a bit hacky. Let's try to find something else let s = &mut *((self as *const Table) as *mut Table); s.rows.shrink_to_fit(); - transmute(self) + &*(self as *const Table as *const TableSlice<'a>) } } } diff --git a/src/row.rs b/src/row.rs index 856a8e0..5f34a24 100644 --- a/src/row.rs +++ b/src/row.rs @@ -66,7 +66,7 @@ impl Row { pub fn get_column_width(&self, column: usize, format: &TableFormat) -> usize { let mut i = 0; for c in &self.cells { - if i + c.get_hspan()-1 >= column { + if i + c.get_hspan() > column { if c.get_hspan() == 1 { return c.get_width(); } -- cgit v1.2.3