Skip to content

Commit 29d26f5

Browse files
committed
Remove generics from NSValue, and add NSNumber
1 parent ed4f140 commit 29d26f5

12 files changed

+643
-148
lines changed

objc2/CHANGELOG_FOUNDATION.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,21 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
## Unreleased - YYYY-MM-DD
1010

1111
### Added
12+
* Added `NSNumber`.
1213
* Implement `UnwindSafe` and `RefUnwindSafe` for all objects.
1314
* Implemented `IntoIterator` for references to `NSArray`, `NSMutableArray`,
1415
`NSData` and `NSMutableData`.
1516
* Implemented `Extend` for `NSMutableArray`.
1617
* Add extra `Extend<&u8>` impl for `NSMutableData`.
18+
* Added function `NSValue::contains_encoding` for determining if the encoding
19+
of the `NSValue` matches the encoding of the given type.
1720

1821
### Changed
1922
* **BREAKING**: Moved from external crate `objc2_foundation` into
2023
`objc2::foundation`.
24+
* **BREAKING**: Made `NSValue` not generic any more. While we loose some
25+
type-safety from this, it makes `NSValue` much more useful in the real
26+
world!
2127

2228
### Fixed
2329
* Made `Debug` impls for all objects print something useful.

objc2/src/foundation/array.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ mod tests {
243243
use alloc::vec::Vec;
244244

245245
use super::*;
246-
use crate::foundation::{NSString, NSValue};
246+
use crate::foundation::{NSNumber, NSString};
247247
use crate::rc::autoreleasepool;
248248

249249
fn sample_array(len: usize) -> Id<NSArray<NSObject, Owned>, Owned> {
@@ -254,10 +254,10 @@ mod tests {
254254
NSArray::from_vec(vec)
255255
}
256256

257-
fn sample_number_array(len: u8) -> Id<NSArray<NSValue<u8>, Shared>, Shared> {
257+
fn sample_number_array(len: u8) -> Id<NSArray<NSNumber, Shared>, Shared> {
258258
let mut vec = Vec::with_capacity(len as usize);
259259
for i in 0..len {
260-
vec.push(NSValue::new(i));
260+
vec.push(NSNumber::new_u8(i));
261261
}
262262
NSArray::from_vec(vec)
263263
}

objc2/src/foundation/enumerator.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,29 +168,29 @@ impl<'a, C: NSFastEnumeration + ?Sized> Iterator for NSFastEnumerator<'a, C> {
168168
#[cfg(test)]
169169
mod tests {
170170
use super::NSFastEnumeration;
171-
use crate::foundation::{NSArray, NSValue};
171+
use crate::foundation::{NSArray, NSNumber};
172172

173173
#[test]
174174
fn test_enumerator() {
175-
let vec = (0usize..4).map(NSValue::new).collect();
175+
let vec = (0..4).map(NSNumber::new_usize).collect();
176176
let array = NSArray::from_vec(vec);
177177

178178
let enumerator = array.iter();
179179
assert_eq!(enumerator.count(), 4);
180180

181181
let enumerator = array.iter();
182-
assert!(enumerator.enumerate().all(|(i, obj)| obj.get() == i));
182+
assert!(enumerator.enumerate().all(|(i, obj)| obj.as_usize() == i));
183183
}
184184

185185
#[test]
186186
fn test_fast_enumerator() {
187-
let vec = (0usize..4).map(NSValue::new).collect();
187+
let vec = (0..4).map(NSNumber::new_usize).collect();
188188
let array = NSArray::from_vec(vec);
189189

190190
let enumerator = array.iter_fast();
191191
assert_eq!(enumerator.count(), 4);
192192

193193
let enumerator = array.iter_fast();
194-
assert!(enumerator.enumerate().all(|(i, obj)| obj.get() == i));
194+
assert!(enumerator.enumerate().all(|(i, obj)| obj.as_usize() == i));
195195
}
196196
}

objc2/src/foundation/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ pub use self::mutable_array::NSMutableArray;
3939
pub use self::mutable_attributed_string::NSMutableAttributedString;
4040
pub use self::mutable_data::NSMutableData;
4141
pub use self::mutable_string::NSMutableString;
42+
pub use self::number::NSNumber;
4243
pub use self::object::NSObject;
4344
pub use self::process_info::NSProcessInfo;
4445
pub use self::range::NSRange;
@@ -77,6 +78,7 @@ mod mutable_array;
7778
mod mutable_attributed_string;
7879
mod mutable_data;
7980
mod mutable_string;
81+
mod number;
8082
mod object;
8183
mod process_info;
8284
mod range;
@@ -141,6 +143,7 @@ mod tests {
141143
assert_auto_traits::<NSMutableAttributedString>();
142144
assert_auto_traits::<NSMutableData>();
143145
assert_auto_traits::<NSMutableString>();
146+
assert_auto_traits::<NSNumber>();
144147
// assert_auto_traits::<NSObject>(); // Intentional
145148
assert_auto_traits::<NSProcessInfo>();
146149
assert_auto_traits::<NSRange>();
@@ -149,7 +152,7 @@ mod tests {
149152
assert_auto_traits::<NSThread>();
150153
#[cfg(not(macos_10_7))]
151154
assert_auto_traits::<NSUUID>();
152-
assert_auto_traits::<NSValue<i32>>();
155+
// assert_auto_traits::<NSValue>(); // Intentional
153156
assert_unwindsafe::<NSZone>(); // Intentional
154157
}
155158
}

0 commit comments

Comments
 (0)