Skip to content

Commit

Permalink
Remove non-meaningful implementations of Ord
Browse files Browse the repository at this point in the history
Removes `PartialOrd` and `Ord` from:
- `WindowId`
- `DeviceId`
- `FingerId`
- `MonitorHandle`
- `VideoModeHandle`
  • Loading branch information
daxpedda committed Aug 14, 2024
1 parent 7fbc211 commit e9a4e0b
Show file tree
Hide file tree
Showing 24 changed files with 42 additions and 159 deletions.
2 changes: 2 additions & 0 deletions src/changelog/unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ changelog entry.
- Remove `MonitorHandle::size()` and `refresh_rate_millihertz()` in favor of
`MonitorHandle::current_video_mode()`.
- On Android, remove all `MonitorHandle` support instead of emitting false data.
- Remove `PartialOrd` and `Ord` implementations from `WindowId`, `DeviceId`, `MonitorHandle` and
`VideoModeHandle`.

### Fixed

Expand Down
11 changes: 3 additions & 8 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ pub enum WindowEvent {
/// `DeviceId` which identifies its origin. Note that devices may be virtual (representing an
/// on-screen cursor and keyboard focus) or physical. Virtual devices typically aggregate inputs
/// from multiple physical devices.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DeviceId(pub(crate) platform_impl::DeviceId);

impl Default for DeviceId {
Expand All @@ -457,7 +457,7 @@ impl DeviceId {
///
/// Whenever a touch event is received it contains a `FingerId` which uniquely identifies the finger
/// used for the current interaction.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FingerId(pub(crate) platform_impl::FingerId);

impl FingerId {
Expand Down Expand Up @@ -1032,7 +1032,7 @@ impl Eq for InnerSizeWriter {}

#[cfg(test)]
mod tests {
use std::collections::{BTreeSet, HashSet};
use std::collections::HashSet;

use crate::dpi::PhysicalPosition;
use crate::event;
Expand Down Expand Up @@ -1166,11 +1166,6 @@ mod tests {
let did = crate::event::DeviceId::dummy().clone();
let fid = crate::event::FingerId::dummy().clone();
HashSet::new().insert(did);
let mut set = [did, did, did];
set.sort_unstable();
let mut set2 = BTreeSet::new();
set2.insert(did);
set2.insert(did);

HashSet::new().insert(event::TouchPhase::Started.clone());
HashSet::new().insert(event::MouseButton::Left.clone());
Expand Down
23 changes: 1 addition & 22 deletions src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,27 +24,6 @@ impl std::fmt::Debug for VideoModeHandle {
}
}

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

impl Ord for VideoModeHandle {
fn cmp(&self, other: &VideoModeHandle) -> std::cmp::Ordering {
self.monitor().cmp(&other.monitor()).then(
self.size()
.cmp(&other.size())
.then(
self.refresh_rate_millihertz()
.cmp(&other.refresh_rate_millihertz())
.then(self.bit_depth().cmp(&other.bit_depth())),
)
.reverse(),
)
}
}

impl VideoModeHandle {
/// Returns the resolution of this video mode. This **must not** be used to create your
/// rendering surface. Use [`Window::inner_size()`] instead.
Expand Down Expand Up @@ -112,7 +91,7 @@ impl std::fmt::Display for VideoModeHandle {
/// to check.
///
/// [`Window`]: crate::window::Window
#[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Clone, PartialEq, Eq, Hash)]
pub struct MonitorHandle {
pub(crate) inner: platform_impl::MonitorHandle,
}
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/android/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,7 @@ impl OwnedDisplayHandle {
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub(crate) struct WindowId;

impl WindowId {
Expand All @@ -687,7 +687,7 @@ impl From<u64> for WindowId {
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct DeviceId(i32);

impl DeviceId {
Expand All @@ -696,7 +696,7 @@ impl DeviceId {
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct FingerId(i32);

impl FingerId {
Expand Down Expand Up @@ -947,7 +947,7 @@ impl Display for OsError {
}
}

#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
pub struct MonitorHandle;

impl MonitorHandle {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/apple/appkit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ use crate::event::DeviceId as RootDeviceId;
pub(crate) use crate::icon::NoIcon as PlatformIcon;
pub(crate) use crate::platform_impl::Fullscreen;

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DeviceId;

impl DeviceId {
Expand All @@ -43,7 +43,7 @@ impl DeviceId {
// Constant device ID; to be removed when if backend is updated to report real device IDs.
pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FingerId;

impl FingerId {
Expand Down
15 changes: 0 additions & 15 deletions src/platform_impl/apple/appkit/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,21 +147,6 @@ impl PartialEq for MonitorHandle {

impl Eq for MonitorHandle {}

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

impl Ord for MonitorHandle {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
unsafe {
ffi::CGDisplayCreateUUIDFromDisplayID(self.0)
.cmp(&ffi::CGDisplayCreateUUIDFromDisplayID(other.0))
}
}
}

impl std::hash::Hash for MonitorHandle {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
unsafe {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/apple/appkit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ impl Window {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct WindowId(pub usize);

impl WindowId {
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/apple/uikit/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub(crate) use crate::platform_impl::Fullscreen;
/// UIKit (i.e. you can't differentiate between different external keyboards,
/// or whether it was the main touchscreen, assistive technologies, or some
/// other pointer device that caused a touch event).
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DeviceId;

impl DeviceId {
Expand All @@ -37,7 +37,7 @@ impl DeviceId {

pub(crate) const DEVICE_ID: RootDeviceId = RootDeviceId(DeviceId);

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FingerId(usize);

impl FingerId {
Expand Down
17 changes: 2 additions & 15 deletions src/platform_impl/apple/uikit/monitor.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![allow(clippy::unnecessary_cast)]

use std::collections::{BTreeSet, VecDeque};
use std::collections::VecDeque;
use std::num::{NonZeroU16, NonZeroU32};
use std::{fmt, hash, ptr};

Expand Down Expand Up @@ -113,19 +113,6 @@ impl PartialEq for MonitorHandle {

impl Eq for MonitorHandle {}

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

impl Ord for MonitorHandle {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
// TODO: Make a better ordering
(self as *const Self).cmp(&(other as *const Self))
}
}

impl fmt::Debug for MonitorHandle {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("MonitorHandle")
Expand Down Expand Up @@ -185,7 +172,7 @@ impl MonitorHandle {
let ui_screen = self.ui_screen(mtm);
// Use Ord impl of RootVideoModeHandle

let modes: BTreeSet<_> = ui_screen
let modes: Vec<_> = ui_screen
.availableModes()
.into_iter()
.map(|mode| RootVideoModeHandle {
Expand Down
2 changes: 1 addition & 1 deletion src/platform_impl/apple/uikit/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -670,7 +670,7 @@ impl Inner {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct WindowId {
window: *mut WinitUIWindow,
}
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ pub(crate) enum Window {
Wayland(wayland::Window),
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct WindowId(u64);

impl From<WindowId> for u64 {
Expand All @@ -161,7 +161,7 @@ impl WindowId {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum DeviceId {
#[cfg(x11_platform)]
X(x11::DeviceId),
Expand All @@ -178,7 +178,7 @@ impl DeviceId {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub enum FingerId {
#[cfg(x11_platform)]
X(x11::FingerId),
Expand All @@ -195,7 +195,7 @@ impl FingerId {
}
}

#[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub enum MonitorHandle {
#[cfg(x11_platform)]
X(x11::MonitorHandle),
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ impl From<WaylandError> for OsError {
}

/// Dummy device id, since Wayland doesn't have device events.
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DeviceId;

impl DeviceId {
Expand All @@ -71,7 +71,7 @@ impl DeviceId {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FingerId(i32);

impl FingerId {
Expand Down
12 changes: 0 additions & 12 deletions src/platform_impl/linux/wayland/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,6 @@ impl PartialEq for MonitorHandle {

impl Eq for MonitorHandle {}

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

impl Ord for MonitorHandle {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.native_identifier().cmp(&other.native_identifier())
}
}

impl std::hash::Hash for MonitorHandle {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.native_identifier().hash(state);
Expand Down
4 changes: 2 additions & 2 deletions src/platform_impl/linux/x11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ impl<'a> Deref for DeviceInfo<'a> {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct DeviceId(xinput::DeviceId);

impl DeviceId {
Expand All @@ -817,7 +817,7 @@ impl DeviceId {
}
}

#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub struct FingerId(u32);

impl FingerId {
Expand Down
12 changes: 0 additions & 12 deletions src/platform_impl/linux/x11/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,18 +76,6 @@ impl PartialEq for MonitorHandle {

impl Eq for MonitorHandle {}

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

impl Ord for MonitorHandle {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.id.cmp(&other.id)
}
}

impl std::hash::Hash for MonitorHandle {
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
self.id.hash(state);
Expand Down
8 changes: 4 additions & 4 deletions src/platform_impl/orbital/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ impl TimeSocket {
#[derive(Default, Debug, Copy, Clone, PartialEq, Eq, Hash)]
pub(crate) struct PlatformSpecificEventLoopAttributes {}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct WindowId {
fd: u64,
}
Expand All @@ -119,7 +119,7 @@ impl From<u64> for WindowId {
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct DeviceId;

impl DeviceId {
Expand All @@ -128,7 +128,7 @@ impl DeviceId {
}
}

#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub struct FingerId;

impl FingerId {
Expand Down Expand Up @@ -193,7 +193,7 @@ pub(crate) use crate::cursor::{
};
pub(crate) use crate::icon::NoIcon as PlatformIcon;

#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
pub struct MonitorHandle;

impl MonitorHandle {
Expand Down
Loading

0 comments on commit e9a4e0b

Please sign in to comment.