Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: madsmtm/objc2
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 7508af1912ed8b5f967e43b233e7f8637667600f
Choose a base ref
..
head repository: madsmtm/objc2
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 60963e3f473d3db1d55be13da4e7c1a27ba36ac5
Choose a head ref
2 changes: 1 addition & 1 deletion crates/icrate/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -57,7 +57,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
* **BREAKING**: Removed the `MainThreadMarker` argument from the closure
passed to `MainThreadBound::get_on_main`.
* **BREAKING**: Removed `Foundation::CopyHelper` since it is superseded by
`objc2::mutability::CounterpartOrSelf`
`objc2::mutability::CounterpartOrSelf`.

### Fixed
* **BREAKING**: Added `Eq + Hash` requirement on most `NSDictionary` and
8 changes: 4 additions & 4 deletions crates/icrate/src/additions/Foundation/dictionary.rs
Original file line number Diff line number Diff line change
@@ -27,8 +27,8 @@ impl<K: Message + Eq + Hash + HasStableHash, V: Message> NSDictionary<K, V> {
// Find the minimum of the two provided lengths, to ensure that we
// don't read too far in one of the buffers.
//
// Note: We could also have chosen to just panic here, either would
// be fine.
// Note: We could also have chosen to just panic here if the buffers have
// different lengths, either would be fine.
let count = min(keys.len(), objects.len());

let keys: *mut NonNull<Q> = util::ref_ptr_cast_const(keys.as_ptr());
@@ -142,8 +142,8 @@ impl<K: Message + Eq + Hash + HasStableHash, V: Message> NSMutableDictionary<K,
// trait, since we don't control how the comparisons happen.
//
// The most useful alternative would probably be to take
// `impl AsRef<K>`, but type deref to their superclass anyhow, let's
// just use a simple normal reference.
// `impl AsRef<K>`, but objc2 classes deref to their superclass anyhow, so
// let's just use a simple normal reference.

extern_methods!(
unsafe impl<K: Message + Eq + Hash, V: Message> NSDictionary<K, V> {
13 changes: 13 additions & 0 deletions crates/icrate/tests/dictionary.rs
Original file line number Diff line number Diff line change
@@ -98,3 +98,16 @@ fn test_debug() {
let dict = NSDictionary::from_id_slice(&[&*key], &[val]);
assert_eq!(format!("{dict:?}"), r#"{"a": "b"}"#);
}

#[test]
fn new_different_lengths() {
let dict = NSDictionary::from_id_slice(
&[
&*NSString::from_str("a"),
&*NSString::from_str("b"),
&*NSString::from_str("c"),
],
&[NSObject::new(), NSObject::new()],
);
assert_eq!(dict.len(), 2);
}
12 changes: 12 additions & 0 deletions crates/icrate/tests/mutable_dictionary.rs
Original file line number Diff line number Diff line change
@@ -32,6 +32,18 @@ fn sample_dict_mut() -> Id<NSMutableDictionary<NSNumber, icrate::Foundation::NSM
)
}

#[test]
#[cfg(feature = "Foundation_NSMutableString")]
fn dict_from_mutable() {
let _: Id<NSMutableDictionary<icrate::Foundation::NSString, icrate::Foundation::NSString>> =
NSMutableDictionary::from_id_slice(
&[&*icrate::Foundation::NSMutableString::from_str("a")],
&[Id::into_super(
icrate::Foundation::NSMutableString::from_str("b"),
)],
);
}

#[test]
fn test_new() {
let dict = NSMutableDictionary::<NSObject, NSObject>::new();
2 changes: 2 additions & 0 deletions crates/objc2/src/mutability.rs
Original file line number Diff line number Diff line change
@@ -422,6 +422,8 @@ impl<T: ?Sized + ClassType> IsMainThreadOnly for T where
/// and `isEqual:` methods are required to not use external sources like
/// thread locals or randomness to determine their result, we can guarantee
/// that the hash is stable for these types.
//
// TODO: Exclude generic types like `NSArray<NSView>` from this!
pub trait HasStableHash: ClassType {}
impl<T: ?Sized + ClassType> HasStableHash for T where T::Mutability: private::MutabilityHashIsStable {}