use crate::mutability::{
Immutable, ImmutableWithMutableSubclass, InteriorMutable, MainThreadOnly, Mutable,
MutableWithImmutableSuperclass, Root,
};
use crate::rc::Id;
use crate::{msg_send_id, ClassType, ProtocolType};
pub trait Copyhelper<T: ?Sized> {
type CopyOutput: ?Sized + ClassType;
type MutableCopyOutput: ?Sized + ClassType;
#[doc(hidden)]
fn __do_copy(t: &T) -> Id<T>;
}
impl<T: NSCopying + ClassType<Mutability = Root>> Copyhelper<T> for Root {
type CopyOutput = T;
type MutableCopyOutput = T;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.copy()
}
}
impl<T: NSCopying + ClassType<Mutability = Immutable>> Copyhelper<T> for Immutable {
type CopyOutput = T;
type MutableCopyOutput = T;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.retain()
}
}
impl<T: NSCopying + ClassType<Mutability = Mutable>> Copyhelper<T> for Mutable {
type CopyOutput = T;
type MutableCopyOutput = T;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.copy()
}
}
impl<T, S> Copyhelper<T> for ImmutableWithMutableSubclass<S>
where
T: NSCopying + ClassType<Mutability = ImmutableWithMutableSubclass<S>>,
S: ClassType<Mutability = MutableWithImmutableSuperclass<T>>,
{
type CopyOutput = T;
type MutableCopyOutput = S;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.copy()
}
}
impl<T, S> Copyhelper<T> for MutableWithImmutableSuperclass<S>
where
T: NSMutableCopying + ClassType<Mutability = MutableWithImmutableSuperclass<S>>,
S: ClassType<Mutability = ImmutableWithMutableSubclass<T>>,
{
type CopyOutput = S;
type MutableCopyOutput = T;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.mutableCopy()
}
}
impl<T: NSCopying + ClassType<Mutability = InteriorMutable>> Copyhelper<T> for InteriorMutable {
type CopyOutput = T;
type MutableCopyOutput = T;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.retain()
}
}
impl<T: NSCopying + ClassType<Mutability = MainThreadOnly>> Copyhelper<T> for MainThreadOnly {
type CopyOutput = T;
type MutableCopyOutput = T;
#[inline]
fn __do_copy(t: &T) -> Id<T> {
t.retain()
}
}
#[allow(clippy::missing_safety_doc)] pub unsafe trait NSCopying {
fn copy(&self) -> Id<<Self::Mutability as Copyhelper<Self>>::CopyOutput>
where
Self: Sized + ClassType,
Self::Mutability: Copyhelper<Self>,
{
unsafe { msg_send_id![self, copy] }
}
}
crate::__inner_extern_protocol!(
()
(NSCopying)
(dyn NSCopying)
("NSCopying")
);
#[allow(clippy::missing_safety_doc)] pub unsafe trait NSMutableCopying {
#[allow(non_snake_case)]
fn mutableCopy(&self) -> Id<<Self::Mutability as Copyhelper<Self>>::MutableCopyOutput>
where
Self: Sized + ClassType,
Self::Mutability: Copyhelper<Self>,
{
unsafe { msg_send_id![self, mutableCopy] }
}
}
crate::__inner_extern_protocol!(
()
(NSMutableCopying)
(dyn NSMutableCopying)
("NSMutableCopying")
);