Skip to content

Commit 21ef137

Browse files
committed
refactor: make the default comparison by data and not by id
1 parent 012bbfb commit 21ef137

2 files changed

Lines changed: 19 additions & 4 deletions

File tree

src/app.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub enum Page {
2929

3030
/// The types of arrow keys
3131
#[allow(dead_code)]
32-
#[derive(Debug, Clone)]
32+
#[derive(Debug, Clone, PartialEq)]
3333
pub enum ArrowKey {
3434
Up,
3535
Down,
@@ -38,7 +38,7 @@ pub enum ArrowKey {
3838
}
3939

4040
/// The ways the cursor can move when a key is pressed
41-
#[derive(Debug, Clone)]
41+
#[derive(Debug, Clone, PartialEq)]
4242
pub enum Move {
4343
Back,
4444
Forwards(String),

src/app/apps.rs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,19 @@ pub enum AppCommand {
3030
Display,
3131
}
3232

33+
impl PartialEq for AppCommand {
34+
fn eq(&self, other: &Self) -> bool {
35+
// TODO: make an *actual* impl of PartialEq for Message
36+
match (&self, &other) {
37+
(Self::Function(a), Self::Function(b)) => a == b,
38+
(Self::Display, Self::Display) => true,
39+
_ => false
40+
}
41+
}
42+
}
43+
3344
/// A container for [`App`] data specific to a certain type of app.
34-
#[derive(Debug, Clone)]
45+
#[derive(Debug, Clone, PartialEq)]
3546
pub enum AppData {
3647
/// A platform specific executable
3748
Executable {
@@ -83,11 +94,15 @@ pub struct App {
8394

8495
impl PartialEq for App {
8596
fn eq(&self, other: &Self) -> bool {
86-
self.id == other.id
97+
self.app_data == other.app_data &&
98+
self.name == other.name
8799
}
88100
}
89101

90102
impl App {
103+
/// Get the internal id
104+
pub fn id(&self) -> usize { self.id }
105+
91106
/// Creates a new instance
92107
pub fn new(name: &str, name_lc: &str, desc: &str, data: AppData) -> Self {
93108
static ID: AtomicUsize = AtomicUsize::new(0);

0 commit comments

Comments
 (0)