|
3 | 3 | // |
4 | 4 | // SPDX-License-Identifier: MIT OR Apache-2.0 |
5 | 5 |
|
6 | | -use std::fmt::Debug; |
7 | | -use std::hash::Hash; |
8 | | -use std::ops::{BitAnd, BitAndAssign, BitOr, BitOrAssign, BitXor, BitXorAssign, Not}; |
| 6 | +use super::QFlagRepr; |
9 | 7 |
|
10 | 8 | use cxx::ExternType; |
11 | 9 |
|
12 | | -pub trait QFlagRepr: Sized { |
13 | | - /// Qt chooses the integer representation for a `QFlags<T>` as follows: |
14 | | - /// |
15 | | - /// - If `T` is signed, use a signed integer. Otherwise, use an unsigned integer. |
16 | | - /// - If `T` is 32 bits or less, use a 32-bit integer. |
17 | | - /// - If `T` is 64 bits and the Qt version is at least 6.9, use a 64-bit integer. |
18 | | - type Int: From<Self> |
19 | | - + Copy |
20 | | - + Debug |
21 | | - + Default |
22 | | - + Eq |
23 | | - + Ord |
24 | | - + Hash |
25 | | - + BitAnd<Output = Self::Int> |
26 | | - + BitAndAssign |
27 | | - + BitOr<Output = Self::Int> |
28 | | - + BitOrAssign |
29 | | - + BitXor<Output = Self::Int> |
30 | | - + BitXorAssign |
31 | | - + Not<Output = Self::Int> |
32 | | - + ExternType<Kind = cxx::kind::Trivial>; |
33 | | - |
34 | | - const ZERO: Self::Int; |
35 | | -} |
36 | | - |
37 | | -macro_rules! impl_repr { |
38 | | - ($t:ty, $i:ty) => { |
39 | | - impl QFlagRepr for $t { |
40 | | - type Int = $i; |
41 | | - |
42 | | - const ZERO: Self::Int = 0; |
43 | | - } |
44 | | - }; |
45 | | -} |
46 | | - |
47 | | -impl_repr!(i8, i32); |
48 | | -impl_repr!(i16, i32); |
49 | | -impl_repr!(i32, i32); |
50 | | -impl_repr!(u8, u32); |
51 | | -impl_repr!(u16, u32); |
52 | | -impl_repr!(u32, u32); |
53 | | - |
54 | | -#[cfg(cxxqt_qt_version_at_least_6_9)] |
55 | | -impl_repr!(i64, i64); |
56 | | -#[cfg(cxxqt_qt_version_at_least_6_9)] |
57 | | -impl_repr!(u64, u64); |
58 | | - |
59 | 10 | /// # Safety |
60 | 11 | /// |
61 | 12 | /// By writing the unsafe `QFlag` impl, the programmer asserts that the C++ namespace and type name |
@@ -90,17 +41,13 @@ pub unsafe trait QFlag: Sized { |
90 | 41 | } |
91 | 42 |
|
92 | 43 | /// Internal utility trait for converting `T` in a `QFlag<T>` to the corresponding integer type. |
93 | | -pub trait QFlagExt: QFlag { |
94 | | - type Int; |
95 | | - |
96 | | - fn to_int(self) -> Self::Int; |
| 44 | +pub(super) trait QFlagExt: QFlag { |
| 45 | + fn to_int(self) -> <Self::Repr as QFlagRepr>::Int; |
97 | 46 | } |
98 | 47 |
|
99 | 48 | impl<T: QFlag> QFlagExt for T { |
100 | | - type Int = <<T as QFlag>::Repr as QFlagRepr>::Int; |
101 | | - |
102 | 49 | #[inline(always)] |
103 | | - fn to_int(self) -> Self::Int { |
| 50 | + fn to_int(self) -> <Self::Repr as QFlagRepr>::Int { |
104 | 51 | self.to_repr().into() |
105 | 52 | } |
106 | 53 | } |
0 commit comments