Added sorting for cards

This commit is contained in:
2025-08-21 03:30:04 +01:00
parent 6b5034c544
commit 821d301de3
3 changed files with 35 additions and 9 deletions

View File

@@ -1,5 +1,6 @@
use deunicode::deunicode;
use rusqlite;
use std::cmp::Ordering;
use std::fmt;
use std::fs;
use std::path::PathBuf;
@@ -75,6 +76,26 @@ impl fmt::Display for DbCard {
}
}
impl Ord for DbCard {
fn cmp(&self, other: &Self) -> Ordering {
self.name.cmp(&other.name)
}
}
impl PartialOrd for DbCard {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl PartialEq for DbCard {
fn eq(&self, other: &Self) -> bool {
self.name == other.name
}
}
impl Eq for DbCard {}
#[derive(Debug)]
pub struct DbCard {
pub name: String,

View File

@@ -92,7 +92,7 @@ fn main() -> MtgCardExit {
return res;
}
let matching_cards = find_matching_cards_scryfall_style(&args.search_text);
let mut matching_cards = find_matching_cards_scryfall_style(&args.search_text);
dbg!(&args.search_text);
dbg!(&matching_cards);
@@ -119,6 +119,7 @@ fn main() -> MtgCardExit {
// TODO update this to be more meaningful
return MtgCardExit::ExactCardFound;
} else {
matching_cards.sort();
for card in matching_cards {
println!(
"{}",