Skip to content

Commit 1ffa8ee

Browse files
committed
Create associated constants Bool::YES and Bool::NO from objc2_sys
1 parent 76ce0e9 commit 1ffa8ee

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

objc2/src/bool.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
use objc2_sys::BOOL;
2-
31
use crate::{Encode, Encoding, RefEncode};
42
use core::fmt;
53

@@ -15,35 +13,35 @@ use core::fmt;
1513
// something that is not 0 or 1 into the Bool?
1614
#[derive(Copy, Clone, Default, Ord, PartialOrd, Eq, PartialEq, Hash)]
1715
pub struct Bool {
18-
value: BOOL,
16+
value: objc2_sys::BOOL,
1917
}
2018

2119
impl Bool {
2220
/// The equivalent of [`true`] for Objective-C's `BOOL` type.
23-
pub const YES: Self = Self::new(true);
21+
pub const YES: Self = Self::from_raw(objc2_sys::YES);
2422

2523
/// The equivalent of [`false`] for Objective-C's `BOOL` type.
26-
pub const NO: Self = Self::new(false);
24+
pub const NO: Self = Self::from_raw(objc2_sys::NO);
2725

2826
/// Creates an Objective-C boolean from a Rust boolean.
2927
#[inline]
3028
pub const fn new(value: bool) -> Self {
3129
// true as u8 => 1
3230
// false as u8 => 0
33-
let value = value as BOOL;
31+
let value = value as objc2_sys::BOOL;
3432
Self { value }
3533
}
3634

3735
/// Creates this from a boolean value received from a raw Objective-C API.
3836
#[inline]
39-
pub const fn from_raw(value: BOOL) -> Self {
37+
pub const fn from_raw(value: objc2_sys::BOOL) -> Self {
4038
Self { value }
4139
}
4240

4341
/// Retrieves the inner `objc2_sys` boolean type, to be used in raw
4442
/// Objective-C APIs.
4543
#[inline]
46-
pub const fn as_raw(self) -> BOOL {
44+
pub const fn as_raw(self) -> objc2_sys::BOOL {
4745
self.value
4846
}
4947

@@ -85,7 +83,7 @@ impl fmt::Debug for Bool {
8583
}
8684

8785
unsafe impl Encode for Bool {
88-
const ENCODING: Encoding<'static> = BOOL::ENCODING;
86+
const ENCODING: Encoding<'static> = objc2_sys::BOOL::ENCODING;
8987
}
9088

9189
unsafe impl RefEncode for Bool {

objc2/src/declare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -323,8 +323,8 @@ impl ProtocolDecl {
323323
self.proto as _,
324324
sel.as_ptr() as _,
325325
types.as_ptr(),
326-
Bool::new(is_required).into(),
327-
Bool::new(is_instance_method).into(),
326+
Bool::new(is_required).as_raw(),
327+
Bool::new(is_instance_method).as_raw(),
328328
);
329329
}
330330
}

0 commit comments

Comments
 (0)