Skip to content

Commit

Permalink
Remove weird implementation of PartialEq for Cell
Browse files Browse the repository at this point in the history
  • Loading branch information
ogham committed Apr 26, 2020
1 parent 7eea57a commit 2d92370
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@

use std::cmp::max;
use std::convert;
use std::cmp::{Ord, Ordering};
use std::fmt;
use std::iter::repeat;

Expand All @@ -130,7 +129,7 @@ pub enum Alignment {
/// The easiest way to create a Cell is just by using `string.into()`, which
/// uses the **unicode width** of the string (see the `unicode_width` crate).
/// However, the fields are public, if you wish to provide your own length.
#[derive(Debug, Clone)]
#[derive(PartialEq, Debug, Clone)]
pub struct Cell {

/// The string to display when this cell gets rendered.
Expand Down Expand Up @@ -163,25 +162,6 @@ impl<'a> convert::From<&'a str> for Cell {
}
}

impl Ord for Cell {
fn cmp(&self, other: &Self) -> Ordering {
self.width.cmp(&other.width)
}
}

impl PartialOrd for Cell {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

impl PartialEq for Cell {
fn eq(&self, other: &Self) -> bool {
self.width == other.width
}
}

impl Eq for Cell {}

/// Direction cells should be written in — either across, or downwards.
#[derive(PartialEq, Debug, Copy, Clone)]
Expand Down Expand Up @@ -349,7 +329,7 @@ impl Grid {
let mut col_total_width_so_far = 0;

let mut cells = self.cells.clone();
cells.sort_unstable_by(|a, b| b.cmp(a)); // Sort in reverse order
cells.sort_unstable_by(|a, b| b.width.cmp(&a.width)); // Sort in reverse order

for cell in &cells {
if cell.width + col_total_width_so_far <= maximum_width {
Expand Down

0 comments on commit 2d92370

Please sign in to comment.