Skip to content

Commit f41363e

Browse files
committed
Require the Ownership bound on Id
Will allow us to do some nice things when/if GATs stabilize
1 parent e41d1c1 commit f41363e

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

objc2_foundation/src/array.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,11 +190,11 @@ pub trait INSArray: INSObject {
190190
}
191191
}
192192

193-
pub struct NSArray<T, O = Owned> {
193+
pub struct NSArray<T, O: Ownership = Owned> {
194194
item: PhantomData<Id<T, O>>,
195195
}
196196

197-
object_impl!(NSArray<T, O>);
197+
object_impl!(NSArray<T, O: Ownership>);
198198

199199
impl<T, O> INSObject for NSArray<T, O>
200200
where
@@ -340,11 +340,11 @@ pub trait INSMutableArray: INSArray {
340340
}
341341
}
342342

343-
pub struct NSMutableArray<T, O = Owned> {
343+
pub struct NSMutableArray<T, O: Ownership = Owned> {
344344
item: PhantomData<Id<T, O>>,
345345
}
346346

347-
object_impl!(NSMutableArray<T, O>);
347+
object_impl!(NSMutableArray<T, O: Ownership>);
348348

349349
impl<T, O> INSObject for NSMutableArray<T, O>
350350
where

objc2_foundation/src/macros.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ macro_rules! object_impl {
5151
($name:ident) => (
5252
object_impl!($name,);
5353
);
54-
($name:ident<$($t:ident),+>) => (
55-
object_impl!($name, $($t),+);
54+
($name:ident<$($t:ident$(: $b:ident)?),+>) => (
55+
object_impl!($name, $($t$(: $b)?),+);
5656
);
57-
($name:ident, $($t:ident),*) => (
58-
unsafe impl<$($t),*> ::objc2::Message for $name<$($t),*> { }
57+
($name:ident, $($t:ident$(: $b:ident)?),*) => (
58+
unsafe impl<$($t$(:($b))?),*> ::objc2::Message for $name<$($t),*> { }
5959

60-
unsafe impl<$($t),*> ::objc2::RefEncode for $name<$($t),*> {
60+
unsafe impl<$($t$(: $b)?),*> ::objc2::RefEncode for $name<$($t),*> {
6161
const ENCODING_REF: ::objc2::Encoding<'static> = ::objc2::Encoding::Object;
6262
}
6363
);

objc2_id/src/id.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Ownership for Shared {}
9999
/// ```
100100
#[repr(transparent)]
101101
// TODO: Figure out if `Message` bound on `T` would be better here?
102-
pub struct Id<T, O = Owned> {
102+
pub struct Id<T, O: Ownership = Owned> {
103103
/// A pointer to the contained object. The pointer is always retained.
104104
///
105105
/// It is important that this is `NonNull`, since we want to dereference
@@ -311,7 +311,7 @@ impl<T: Message> Clone for Id<T, Shared> {
311311
/// borrowed data.
312312
///
313313
/// [dropck_eyepatch]: https://doc.rust-lang.org/nightly/nomicon/dropck.html#an-escape-hatch
314-
impl<T, O> Drop for Id<T, O> {
314+
impl<T, O: Ownership> Drop for Id<T, O> {
315315
/// Releases the retained object.
316316
///
317317
/// The contained object's destructor (if it has one) is never run!
@@ -354,7 +354,7 @@ unsafe impl<T: Send> Send for Id<T, Owned> {}
354354
/// access as having a `T` directly.
355355
unsafe impl<T: Sync> Sync for Id<T, Owned> {}
356356

357-
impl<T, O> Deref for Id<T, O> {
357+
impl<T, O: Ownership> Deref for Id<T, O> {
358358
type Target = T;
359359

360360
/// Obtain an immutable reference to the object.
@@ -374,7 +374,7 @@ impl<T> DerefMut for Id<T, Owned> {
374374
}
375375
}
376376

377-
impl<T: PartialEq, O> PartialEq for Id<T, O> {
377+
impl<T: PartialEq, O: Ownership> PartialEq for Id<T, O> {
378378
#[inline]
379379
fn eq(&self, other: &Self) -> bool {
380380
(**self).eq(&**other)
@@ -386,9 +386,9 @@ impl<T: PartialEq, O> PartialEq for Id<T, O> {
386386
}
387387
}
388388

389-
impl<T: Eq, O> Eq for Id<T, O> {}
389+
impl<T: Eq, O: Ownership> Eq for Id<T, O> {}
390390

391-
impl<T: PartialOrd, O> PartialOrd for Id<T, O> {
391+
impl<T: PartialOrd, O: Ownership> PartialOrd for Id<T, O> {
392392
#[inline]
393393
fn partial_cmp(&self, other: &Self) -> Option<core::cmp::Ordering> {
394394
(**self).partial_cmp(&**other)
@@ -411,32 +411,32 @@ impl<T: PartialOrd, O> PartialOrd for Id<T, O> {
411411
}
412412
}
413413

414-
impl<T: Ord, O> Ord for Id<T, O> {
414+
impl<T: Ord, O: Ownership> Ord for Id<T, O> {
415415
#[inline]
416416
fn cmp(&self, other: &Self) -> core::cmp::Ordering {
417417
(**self).cmp(&**other)
418418
}
419419
}
420420

421-
impl<T: hash::Hash, O> hash::Hash for Id<T, O> {
421+
impl<T: hash::Hash, O: Ownership> hash::Hash for Id<T, O> {
422422
fn hash<H: hash::Hasher>(&self, state: &mut H) {
423423
(**self).hash(state)
424424
}
425425
}
426426

427-
impl<T: fmt::Display, O> fmt::Display for Id<T, O> {
427+
impl<T: fmt::Display, O: Ownership> fmt::Display for Id<T, O> {
428428
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
429429
(**self).fmt(f)
430430
}
431431
}
432432

433-
impl<T: fmt::Debug, O> fmt::Debug for Id<T, O> {
433+
impl<T: fmt::Debug, O: Ownership> fmt::Debug for Id<T, O> {
434434
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
435435
(**self).fmt(f)
436436
}
437437
}
438438

439-
impl<T, O> fmt::Pointer for Id<T, O> {
439+
impl<T, O: Ownership> fmt::Pointer for Id<T, O> {
440440
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
441441
fmt::Pointer::fmt(&self.ptr.as_ptr(), f)
442442
}
@@ -472,7 +472,7 @@ impl<I: ExactSizeIterator> ExactSizeIterator for Id<I, Owned> {
472472

473473
impl<I: FusedIterator> FusedIterator for Id<I, Owned> {}
474474

475-
impl<T, O> borrow::Borrow<T> for Id<T, O> {
475+
impl<T, O: Ownership> borrow::Borrow<T> for Id<T, O> {
476476
fn borrow(&self) -> &T {
477477
&**self
478478
}
@@ -484,7 +484,7 @@ impl<T> borrow::BorrowMut<T> for Id<T, Owned> {
484484
}
485485
}
486486

487-
impl<T, O> AsRef<T> for Id<T, O> {
487+
impl<T, O: Ownership> AsRef<T> for Id<T, O> {
488488
fn as_ref(&self) -> &T {
489489
&**self
490490
}
@@ -507,7 +507,7 @@ impl<T> AsMut<T> for Id<T, Owned> {
507507
//
508508
// See https://doc.rust-lang.org/1.54.0/src/alloc/boxed.rs.html#1652-1675
509509
// and the `Arc` implementation.
510-
impl<T, O> Unpin for Id<T, O> {}
510+
impl<T, O: Ownership> Unpin for Id<T, O> {}
511511

512512
// TODO: When stabilized impl Fn traits & CoerceUnsized
513513

0 commit comments

Comments
 (0)