From 857e15c65f383a6a41707712e8ccb4641ae28d2d Mon Sep 17 00:00:00 2001 From: Ajeet D'Souza <98ajeet@gmail.com> Date: Thu, 26 Mar 2020 01:13:14 +0530 Subject: [PATCH] Remove conversion to i64 when sorting --- src/util.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/util.rs b/src/util.rs index 53d016b..e4a537f 100644 --- a/src/util.rs +++ b/src/util.rs @@ -3,6 +3,7 @@ use crate::dir::Dir; use crate::env::Env; use crate::types::Epoch; use anyhow::{anyhow, bail, Context, Result}; +use std::cmp::{Ordering, PartialOrd}; use std::io::{Read, Write}; use std::process::{Command, Stdio}; use std::time::SystemTime; @@ -41,7 +42,12 @@ pub fn fzf_helper(now: Epoch, mut dirs: Vec) -> Result> { dir.rank = dir.get_frecency(now); } - dirs.sort_by_key(|dir| std::cmp::Reverse(dir.rank as i64)); + dirs.sort_unstable_by(|dir1, dir2| { + dir1.rank + .partial_cmp(&dir2.rank) + .unwrap_or(Ordering::Equal) + .reverse() + }); for dir in dirs.iter() { // ensure that frecency fits in 4 characters