From f41363e808058b8f3b040218540d984893884535 Mon Sep 17 00:00:00 2001 From: Mads Marquart Date: Thu, 9 Sep 2021 12:27:31 +0200 Subject: [PATCH] Require the Ownership bound on Id Will allow us to do some nice things when/if GATs stabilize --- objc2_foundation/src/array.rs | 8 ++++---- objc2_foundation/src/macros.rs | 10 +++++----- objc2_id/src/id.rs | 28 ++++++++++++++-------------- 3 files changed, 23 insertions(+), 23 deletions(-) diff --git a/objc2_foundation/src/array.rs b/objc2_foundation/src/array.rs index b484ec65b..142288e31 100644 --- a/objc2_foundation/src/array.rs +++ b/objc2_foundation/src/array.rs @@ -190,11 +190,11 @@ pub trait INSArray: INSObject { } } -pub struct NSArray { +pub struct NSArray { item: PhantomData>, } -object_impl!(NSArray); +object_impl!(NSArray); impl INSObject for NSArray where @@ -340,11 +340,11 @@ pub trait INSMutableArray: INSArray { } } -pub struct NSMutableArray { +pub struct NSMutableArray { item: PhantomData>, } -object_impl!(NSMutableArray); +object_impl!(NSMutableArray); impl INSObject for NSMutableArray where diff --git a/objc2_foundation/src/macros.rs b/objc2_foundation/src/macros.rs index 09023c3de..8f41ee6c2 100644 --- a/objc2_foundation/src/macros.rs +++ b/objc2_foundation/src/macros.rs @@ -51,13 +51,13 @@ macro_rules! object_impl { ($name:ident) => ( object_impl!($name,); ); - ($name:ident<$($t:ident),+>) => ( - object_impl!($name, $($t),+); + ($name:ident<$($t:ident$(: $b:ident)?),+>) => ( + object_impl!($name, $($t$(: $b)?),+); ); - ($name:ident, $($t:ident),*) => ( - unsafe impl<$($t),*> ::objc2::Message for $name<$($t),*> { } + ($name:ident, $($t:ident$(: $b:ident)?),*) => ( + unsafe impl<$($t$(:($b))?),*> ::objc2::Message for $name<$($t),*> { } - unsafe impl<$($t),*> ::objc2::RefEncode for $name<$($t),*> { + unsafe impl<$($t$(: $b)?),*> ::objc2::RefEncode for $name<$($t),*> { const ENCODING_REF: ::objc2::Encoding<'static> = ::objc2::Encoding::Object; } ); diff --git a/objc2_id/src/id.rs b/objc2_id/src/id.rs index 01c1aaa46..c3aa59b32 100644 --- a/objc2_id/src/id.rs +++ b/objc2_id/src/id.rs @@ -99,7 +99,7 @@ impl Ownership for Shared {} /// ``` #[repr(transparent)] // TODO: Figure out if `Message` bound on `T` would be better here? -pub struct Id { +pub struct Id { /// A pointer to the contained object. The pointer is always retained. /// /// It is important that this is `NonNull`, since we want to dereference @@ -311,7 +311,7 @@ impl Clone for Id { /// borrowed data. /// /// [dropck_eyepatch]: https://doc.rust-lang.org/nightly/nomicon/dropck.html#an-escape-hatch -impl Drop for Id { +impl Drop for Id { /// Releases the retained object. /// /// The contained object's destructor (if it has one) is never run! @@ -354,7 +354,7 @@ unsafe impl Send for Id {} /// access as having a `T` directly. unsafe impl Sync for Id {} -impl Deref for Id { +impl Deref for Id { type Target = T; /// Obtain an immutable reference to the object. @@ -374,7 +374,7 @@ impl DerefMut for Id { } } -impl PartialEq for Id { +impl PartialEq for Id { #[inline] fn eq(&self, other: &Self) -> bool { (**self).eq(&**other) @@ -386,9 +386,9 @@ impl PartialEq for Id { } } -impl Eq for Id {} +impl Eq for Id {} -impl PartialOrd for Id { +impl PartialOrd for Id { #[inline] fn partial_cmp(&self, other: &Self) -> Option { (**self).partial_cmp(&**other) @@ -411,32 +411,32 @@ impl PartialOrd for Id { } } -impl Ord for Id { +impl Ord for Id { #[inline] fn cmp(&self, other: &Self) -> core::cmp::Ordering { (**self).cmp(&**other) } } -impl hash::Hash for Id { +impl hash::Hash for Id { fn hash(&self, state: &mut H) { (**self).hash(state) } } -impl fmt::Display for Id { +impl fmt::Display for Id { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } -impl fmt::Debug for Id { +impl fmt::Debug for Id { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { (**self).fmt(f) } } -impl fmt::Pointer for Id { +impl fmt::Pointer for Id { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fmt::Pointer::fmt(&self.ptr.as_ptr(), f) } @@ -472,7 +472,7 @@ impl ExactSizeIterator for Id { impl FusedIterator for Id {} -impl borrow::Borrow for Id { +impl borrow::Borrow for Id { fn borrow(&self) -> &T { &**self } @@ -484,7 +484,7 @@ impl borrow::BorrowMut for Id { } } -impl AsRef for Id { +impl AsRef for Id { fn as_ref(&self) -> &T { &**self } @@ -507,7 +507,7 @@ impl AsMut for Id { // // See https://doc.rust-lang.org/1.54.0/src/alloc/boxed.rs.html#1652-1675 // and the `Arc` implementation. -impl Unpin for Id {} +impl Unpin for Id {} // TODO: When stabilized impl Fn traits & CoerceUnsized