Trait objc2::foundation::NSCopying
source · [−]pub unsafe trait NSCopying: Message {
type Ownership: Ownership;
type Output: Message;
fn copy(&self) -> Id<Self::Output, Self::Ownership>ⓘNotable traits for Id<I, Owned>impl<I: Iterator + ?Sized> Iterator for Id<I, Owned> type Item = I::Item;impl<T: Read + ?Sized> Read for Id<T, Owned>impl<T: Write + ?Sized> Write for Id<T, Owned>impl<T: Future + Unpin + ?Sized> Future for Id<T, Owned> type Output = T::Output;
{ ... }
}
Available on crate feature
foundation
only.Required Associated Types
Indicates whether the type is mutable or immutable.
This can be Owned
if and only if copy
creates a new instance,
see the following example:
ⓘ
let x: Id<MyObject, _> = MyObject::new();
// This is valid only if `y` is a new instance. Otherwise `x` and `y`
// would be able to create aliasing mutable references!
let y: Id<MyObject, Owned> = x.copy();
Note that for the same reason, you should be careful when defining
new
methods on your object; e.g. immutable types like NSString
don’t return Id<NSString, Owned>
, because that would allow this
trait to create an aliasing Id<NSString, Shared>
(since sending the
copy
message (and others) does not create a new instance, but
instead just retains the instance).
Provided Methods
sourcefn copy(&self) -> Id<Self::Output, Self::Ownership>ⓘNotable traits for Id<I, Owned>
fn copy(&self) -> Id<Self::Output, Self::Ownership>ⓘNotable traits for Id<I, Owned>impl<I: Iterator + ?Sized> Iterator for Id<I, Owned> type Item = I::Item;impl<T: Read + ?Sized> Read for Id<T, Owned>impl<T: Write + ?Sized> Write for Id<T, Owned>impl<T: Future + Unpin + ?Sized> Future for Id<T, Owned> type Output = T::Output;
Implementors
sourceimpl NSCopying for NSAttributedString
impl NSCopying for NSAttributedString
type Ownership = Shared
type Output = NSAttributedString
sourceimpl NSCopying for NSException
impl NSCopying for NSException
type Ownership = Shared
type Output = NSException
sourceimpl NSCopying for NSMutableAttributedString
impl NSCopying for NSMutableAttributedString
type Ownership = Shared
type Output = NSAttributedString
This is implemented as a shallow copy.
As such, it is only possible when the array’s contents are Shared
.