Skip to content

Commit

Permalink
Small tweaks to CopyHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
madsmtm committed Mar 31, 2023
1 parent 23181e4 commit effb6cc
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions crates/objc2/src/runtime/nscopying.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ pub trait Copyhelper<T: ?Sized> {
type CopyOutput: ?Sized + Message;
type MutableCopyOutput: ?Sized + Message;

// TODO: Use this to autogenerate `ToOwned` impls
#[doc(hidden)]
fn __do_copy(t: &T) -> Id<T>;
}
impl<T: ClassType + NSCopying + Message<Kind = Unknown>> Copyhelper<T> for Unknown {
impl<T: NSCopying + Message<Kind = Unknown>> Copyhelper<T> for Unknown {
type CopyOutput = T;
type MutableCopyOutput = T;

Expand All @@ -21,7 +22,7 @@ impl<T: ClassType + NSCopying + Message<Kind = Unknown>> Copyhelper<T> for Unkno
t.copy()
}
}
impl<T: ClassType + NSCopying + Message<Kind = Immutable>> Copyhelper<T> for Immutable {
impl<T: NSCopying + Message<Kind = Immutable>> Copyhelper<T> for Immutable {
type CopyOutput = T;
type MutableCopyOutput = T;

Expand All @@ -30,7 +31,7 @@ impl<T: ClassType + NSCopying + Message<Kind = Immutable>> Copyhelper<T> for Imm
t.copy()
}
}
impl<T: ClassType + NSCopying + Message<Kind = Mutable>> Copyhelper<T> for Mutable {
impl<T: NSCopying + Message<Kind = Mutable>> Copyhelper<T> for Mutable {
type CopyOutput = T;
type MutableCopyOutput = T;

Expand All @@ -41,8 +42,8 @@ impl<T: ClassType + NSCopying + Message<Kind = Mutable>> Copyhelper<T> for Mutab
}
impl<T, S> Copyhelper<T> for ImmutableWithMutableSubclass<S>
where
T: ClassType + NSCopying + Message<Kind = ImmutableWithMutableSubclass<S>>,
S: ClassType + Message<Kind = MutableWithImmutableSuperclass<T>>,
T: NSCopying + Message<Kind = ImmutableWithMutableSubclass<S>>,
S: Message<Kind = MutableWithImmutableSuperclass<T>>,
{
type CopyOutput = T;
type MutableCopyOutput = S;
Expand All @@ -54,8 +55,8 @@ where
}
impl<T, S> Copyhelper<T> for MutableWithImmutableSuperclass<S>
where
T: ClassType + NSMutableCopying + Message<Kind = MutableWithImmutableSuperclass<S>>,
S: ClassType + Message<Kind = ImmutableWithMutableSubclass<T>>,
T: NSMutableCopying + Message<Kind = MutableWithImmutableSuperclass<S>>,
S: Message<Kind = ImmutableWithMutableSubclass<T>>,
{
type CopyOutput = S;
type MutableCopyOutput = T;
Expand All @@ -65,7 +66,7 @@ where
t.mutableCopy()
}
}
impl<T: ClassType + NSCopying + Message<Kind = InteriorMutable>> Copyhelper<T> for InteriorMutable {
impl<T: NSCopying + Message<Kind = InteriorMutable>> Copyhelper<T> for InteriorMutable {
type CopyOutput = T;
type MutableCopyOutput = T;

Expand All @@ -74,7 +75,7 @@ impl<T: ClassType + NSCopying + Message<Kind = InteriorMutable>> Copyhelper<T> f
t.copy()
}
}
impl<T: ClassType + NSCopying + Message<Kind = MainThreadOnly>> Copyhelper<T> for MainThreadOnly {
impl<T: NSCopying + Message<Kind = MainThreadOnly>> Copyhelper<T> for MainThreadOnly {
type CopyOutput = T;
type MutableCopyOutput = T;

Expand All @@ -100,7 +101,7 @@ pub unsafe trait NSCopying {
/// `NSString`.
fn copy(&self) -> Id<<Self::Kind as Copyhelper<Self>>::CopyOutput>
where
Self: Sized + ClassType,
Self: Sized + Message,
Self::Kind: Copyhelper<Self>,
{
unsafe { msg_send_id![self, copy] }
Expand Down Expand Up @@ -132,9 +133,10 @@ crate::__inner_extern_protocol!(
/// - The `mutableCopy` selector must return an owned object.
/// - TODO: More.
pub unsafe trait NSMutableCopying {
#[allow(non_snake_case)]
fn mutableCopy(&self) -> Id<<Self::Kind as Copyhelper<Self>>::MutableCopyOutput>
where
Self: Sized + ClassType,
Self: Sized + Message,
Self::Kind: Copyhelper<Self>,
{
unsafe { msg_send_id![self, mutableCopy] }
Expand Down

0 comments on commit effb6cc

Please sign in to comment.