Skip to content

Commit a6cbfc9

Browse files
committed
Remove comparison impls on Bool
1 parent 3fe939e commit a6cbfc9

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

objc2/src/bool.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@ use core::fmt;
33

44
/// The Objective-C `BOOL` type.
55
///
6-
/// Usually, you would convert this into a Rust [`bool`] with the
7-
/// [`Bool::is_false`] or [`Bool::is_true`] methods.
6+
/// This is a thin wrapper-type over [`objc2_sys::BOOL`]. It is intended that
7+
/// you convert this into a Rust [`bool`] with the [`Bool::is_false`] or
8+
/// [`Bool::is_true`] methods as soon as possible.
89
///
910
/// This is FFI-safe and can be used in directly with
1011
/// [`msg_send!`][`crate::msg_send`].
1112
///
13+
/// Note that this is able to contain more states than `bool` on some
14+
/// platforms, but these cases should not be relied on!
15+
///
1216
/// # Example
1317
///
1418
/// ```no_run
@@ -19,9 +23,12 @@ use core::fmt;
1923
/// assert!(rtn.is_true());
2024
/// ```
2125
#[repr(transparent)]
22-
// TODO: Might have to implement some of these manually, in case someone puts
23-
// something that is not 0 or 1 into the Bool?
24-
#[derive(Copy, Clone, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
26+
// We don't implement comparison traits because they could be implemented with
27+
// two slightly different semantics:
28+
// - `self.is_true().cmp(other.is_true())`
29+
// - `self.value.cmp(other.value)`
30+
// And it is not immediately clear for users which one was chosen.
31+
#[derive(Copy, Clone, Default)]
2532
pub struct Bool {
2633
value: objc2_sys::BOOL,
2734
}
@@ -48,7 +55,7 @@ impl Bool {
4855
Self { value }
4956
}
5057

51-
/// Retrieves the inner `objc2_sys` boolean type, to be used in raw
58+
/// Retrieves the inner [`objc2_sys`] boolean type, to be used in raw
5259
/// Objective-C APIs.
5360
#[inline]
5461
pub const fn as_raw(self) -> objc2_sys::BOOL {

0 commit comments

Comments
 (0)