Skip to content

Commit f78f09e

Browse files
authored
cxx_qt_lib: remove generic bound from QFlags deriving (#1265)
1 parent cdce7bd commit f78f09e

File tree

1 file changed

+34
-3
lines changed
  • crates/cxx-qt-lib/src/core/qflags

1 file changed

+34
-3
lines changed

crates/cxx-qt-lib/src/core/qflags/mod.rs

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
// SPDX-License-Identifier: MIT OR Apache-2.0
55

66
use cxx::ExternType;
7-
use std::fmt::Debug;
8-
use std::hash::Hash;
7+
use std::fmt::{self, Debug, Formatter};
8+
use std::hash::{Hash, Hasher};
99
use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not};
1010

1111
mod qflag;
@@ -19,7 +19,6 @@ mod util;
1919

2020
/// The `QFlags<T>` class is a template class, where T is an enum type.
2121
/// QFlags are used throughout Qt for storing combinations of enum values.
22-
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
2322
#[repr(transparent)]
2423
pub struct QFlags<T: QFlag> {
2524
repr: <T::Repr as QFlagRepr>::Int,
@@ -33,6 +32,38 @@ impl<T: QFlag> Clone for QFlags<T> {
3332
}
3433
}
3534

35+
impl<T: QFlag> Debug for QFlags<T> {
36+
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
37+
f.debug_struct("QFlags").field("repr", &self.repr).finish()
38+
}
39+
}
40+
41+
impl<T: QFlag> PartialEq for QFlags<T> {
42+
fn eq(&self, other: &Self) -> bool {
43+
self.repr == other.repr
44+
}
45+
}
46+
47+
impl<T: QFlag> Eq for QFlags<T> {}
48+
49+
impl<T: QFlag> PartialOrd for QFlags<T> {
50+
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
51+
Some(self.cmp(other))
52+
}
53+
}
54+
55+
impl<T: QFlag> Ord for QFlags<T> {
56+
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
57+
self.repr.cmp(&other.repr)
58+
}
59+
}
60+
61+
impl<T: QFlag> Hash for QFlags<T> {
62+
fn hash<H: Hasher>(&self, state: &mut H) {
63+
self.repr.hash(state);
64+
}
65+
}
66+
3667
impl<T: QFlag> From<T> for QFlags<T> {
3768
/// Returns the value stored in the QFlags object as an integer.
3869
fn from(value: T) -> Self {

0 commit comments

Comments
 (0)