pub unsafe trait NSCopying {
// Provided methods
fn copy(&self) -> Retained<Self::Result>
where Self: Sized + Message + CopyingHelper { ... }
unsafe fn copyWithZone(&self, zone: *mut NSZone) -> Retained<Self::Result>
where Self: Sized + Message + CopyingHelper { ... }
}Available on crate feature
NSObject only.Expand description
A protocol to provide functional copies of objects.
This is similar to Rust’s Clone trait, along with sharing a few
similarities to the std::borrow::ToOwned trait with regards to the
output type.
To allow using this in a meaningful way in Rust, we have to “enrich”
the implementation by also specifying the resulting type, see
CopyingHelper for details.
See also Apple’s documentation.
§Examples
Implement NSCopying for an externally defined class.
use objc2::extern_class;
use objc2_foundation::{CopyingHelper, NSCopying, NSObject};
extern_class!(
#[unsafe(super(NSObject))]
struct ExampleClass;
);
unsafe impl NSCopying for ExampleClass {}
// Copying ExampleClass returns another ExampleClass.
unsafe impl CopyingHelper for ExampleClass {
type Result = Self;
}Implement NSCopying for a custom class.
use objc2::{define_class, msg_send, AnyThread, DefinedClass};
use objc2::rc::Retained;
use objc2::runtime::NSZone;
use objc2_foundation::{CopyingHelper, NSCopying, NSObject};
define_class!(
#[unsafe(super(NSObject))]
struct CustomClass;
unsafe impl NSCopying for CustomClass {
#[unsafe(method_id(copyWithZone:))]
fn copyWithZone(&self, _zone: *const NSZone) -> Retained<Self> {
// Create new class, and transfer ivars
let new = Self::alloc().set_ivars(self.ivars().clone());
unsafe { msg_send![super(new), init] }
}
}
);
// Copying CustomClass returns another CustomClass.
unsafe impl CopyingHelper for CustomClass {
type Result = Self;
}Provided Methods§
Trait Implementations§
Source§impl ProtocolType for dyn NSCopying
impl ProtocolType for dyn NSCopying
impl<T> ImplementedBy<T> for dyn NSCopying
Implementations on Foreign Types§
impl<T> NSCopying for ProtocolObject<T>
Implementors§
impl NSCopying for NSAffineTransform
Available on crate feature
NSAffineTransform only.impl NSCopying for NSAppleEventDescriptor
Available on crate feature
NSAppleEventDescriptor only.impl NSCopying for NSAppleScript
Available on crate feature
NSAppleScript only.impl NSCopying for NSAttributedString
Available on crate feature
NSAttributedString only.impl NSCopying for NSAttributedStringMarkdownParsingOptions
Available on crate feature
NSAttributedString only.impl NSCopying for NSAttributedStringMarkdownSourcePosition
Available on crate feature
NSAttributedString only.impl NSCopying for NSByteCountFormatter
Available on crate feature
NSByteCountFormatter only.impl NSCopying for NSCachedURLResponse
Available on crate feature
NSURLCache only.impl NSCopying for NSCalendar
Available on crate feature
NSCalendar only.impl NSCopying for NSCalendarDate
Available on crate feature
NSCalendarDate only.impl NSCopying for NSCharacterSet
Available on crate feature
NSCharacterSet only.impl NSCopying for NSComparisonPredicate
Available on crate feature
NSComparisonPredicate only.impl NSCopying for NSCompoundPredicate
Available on crate feature
NSCompoundPredicate only.impl NSCopying for NSData
Available on crate feature
NSData only.impl NSCopying for NSDataDetector
Available on crate feature
NSRegularExpression only.impl NSCopying for NSDate
Available on crate feature
NSDate only.impl NSCopying for NSDateComponents
Available on crate feature
NSCalendar only.impl NSCopying for NSDateComponentsFormatter
Available on crate feature
NSDateComponentsFormatter only.impl NSCopying for NSDateFormatter
Available on crate feature
NSDateFormatter only.impl NSCopying for NSDateInterval
Available on crate feature
NSDateInterval only.impl NSCopying for NSDateIntervalFormatter
Available on crate feature
NSDateIntervalFormatter only.impl NSCopying for NSDecimalNumber
Available on crate feature
NSDecimalNumber only.impl NSCopying for NSDimension
Available on crate feature
NSUnit only.impl NSCopying for NSEnergyFormatter
Available on crate feature
NSEnergyFormatter only.impl NSCopying for NSError
Available on crate feature
NSError only.impl NSCopying for NSException
Available on crate feature
NSException only.impl NSCopying for NSExpression
Available on crate feature
NSExpression only.impl NSCopying for NSExtensionItem
Available on crate feature
NSExtensionItem only.impl NSCopying for NSFileSecurity
Available on crate feature
NSURL only.impl NSCopying for NSFormatter
Available on crate feature
NSFormatter only.impl NSCopying for NSHTTPURLResponse
Available on crate feature
NSURLResponse only.impl NSCopying for NSISO8601DateFormatter
Available on crate feature
NSISO8601DateFormatter only.impl NSCopying for NSIndexPath
Available on crate feature
NSIndexPath only.impl NSCopying for NSIndexSet
Available on crate feature
NSIndexSet only.impl NSCopying for NSInflectionRule
Available on crate feature
NSInflectionRule only.impl NSCopying for NSInflectionRuleExplicit
Available on crate feature
NSInflectionRule only.impl NSCopying for NSItemProvider
Available on crate feature
NSItemProvider only.impl NSCopying for NSLengthFormatter
Available on crate feature
NSLengthFormatter only.impl NSCopying for NSListFormatter
Available on crate feature
NSListFormatter only.impl NSCopying for NSLocale
Available on crate feature
NSLocale only.impl NSCopying for NSLocalizedNumberFormatRule
Available on crate feature
NSLocalizedNumberFormatRule only.impl NSCopying for NSMachPort
Available on crate feature
NSPort only.impl NSCopying for NSMassFormatter
Available on crate feature
NSMassFormatter only.impl NSCopying for NSMeasurementFormatter
Available on crate feature
NSMeasurementFormatter only.impl NSCopying for NSMessagePort
Available on crate feature
NSPort only.impl NSCopying for NSMorphology
Available on crate feature
NSMorphology only.impl NSCopying for NSMorphologyCustomPronoun
Available on crate feature
NSMorphology only.impl NSCopying for NSMorphologyPronoun
Available on crate feature
NSMorphology only.impl NSCopying for NSMutableAttributedString
Available on crate feature
NSAttributedString only.impl NSCopying for NSMutableCharacterSet
Available on crate feature
NSCharacterSet only.impl NSCopying for NSMutableData
Available on crate feature
NSData only.impl NSCopying for NSMutableIndexSet
Available on crate feature
NSIndexSet only.impl NSCopying for NSMutableString
Available on crate feature
NSString only.impl NSCopying for NSMutableURLRequest
Available on crate feature
NSURLRequest only.impl NSCopying for NSNotification
Available on crate feature
NSNotification only.impl NSCopying for NSNull
Available on crate feature
NSNull only.impl NSCopying for NSNumber
Available on crate feature
NSValue only.impl NSCopying for NSNumberFormatter
Available on crate feature
NSNumberFormatter only.impl NSCopying for NSOrthography
Available on crate feature
NSOrthography only.impl NSCopying for NSPersonNameComponents
Available on crate feature
NSPersonNameComponents only.impl NSCopying for NSPersonNameComponentsFormatter
Available on crate feature
NSPersonNameComponentsFormatter only.impl NSCopying for NSPointerArray
Available on crate feature
NSPointerArray only.impl NSCopying for NSPointerFunctions
Available on crate feature
NSPointerFunctions only.impl NSCopying for NSPort
Available on crate feature
NSPort only.impl NSCopying for NSPredicate
Available on crate feature
NSPredicate only.impl NSCopying for NSPresentationIntent
Available on crate feature
NSAttributedString only.impl NSCopying for NSRegularExpression
Available on crate feature
NSRegularExpression only.impl NSCopying for NSRelativeDateTimeFormatter
Available on crate feature
NSRelativeDateTimeFormatter only.impl NSCopying for NSScanner
Available on crate feature
NSScanner only.impl NSCopying for NSSocketPort
Available on crate feature
NSPort only.impl NSCopying for NSSortDescriptor
Available on crate feature
NSSortDescriptor only.impl NSCopying for NSString
Available on crate feature
NSString only.impl NSCopying for NSTermOfAddress
Available on crate feature
NSTermOfAddress only.impl NSCopying for NSTextCheckingResult
Available on crate feature
NSTextCheckingResult only.impl NSCopying for NSTimeZone
Available on crate feature
NSTimeZone only.impl NSCopying for NSURL
Available on crate feature
NSURL only.impl NSCopying for NSURLComponents
Available on crate feature
NSURL only.impl NSCopying for NSURLCredential
Available on crate feature
NSURLCredential only.impl NSCopying for NSURLProtectionSpace
Available on crate feature
NSURLProtectionSpace only.impl NSCopying for NSURLQueryItem
Available on crate feature
NSURL only.impl NSCopying for NSURLRequest
Available on crate feature
NSURLRequest only.impl NSCopying for NSURLResponse
Available on crate feature
NSURLResponse only.impl NSCopying for NSURLSessionConfiguration
Available on crate feature
NSURLSession only.impl NSCopying for NSURLSessionDataTask
Available on crate feature
NSURLSession only.impl NSCopying for NSURLSessionDownloadTask
Available on crate feature
NSURLSession only.impl NSCopying for NSURLSessionStreamTask
Available on crate feature
NSURLSession only.impl NSCopying for NSURLSessionTask
Available on crate feature
NSURLSession only.impl NSCopying for NSURLSessionUploadTask
Available on crate feature
NSURLSession only.impl NSCopying for NSURLSessionWebSocketTask
Available on crate feature
NSURLSession only.impl NSCopying for NSUUID
Available on crate feature
NSUUID only.impl NSCopying for NSUnit
Available on crate feature
NSUnit only.impl NSCopying for NSUnitAcceleration
Available on crate feature
NSUnit only.impl NSCopying for NSUnitAngle
Available on crate feature
NSUnit only.impl NSCopying for NSUnitArea
Available on crate feature
NSUnit only.impl NSCopying for NSUnitConcentrationMass
Available on crate feature
NSUnit only.impl NSCopying for NSUnitDispersion
Available on crate feature
NSUnit only.impl NSCopying for NSUnitDuration
Available on crate feature
NSUnit only.impl NSCopying for NSUnitElectricCharge
Available on crate feature
NSUnit only.impl NSCopying for NSUnitElectricCurrent
Available on crate feature
NSUnit only.impl NSCopying for NSUnitElectricPotentialDifference
Available on crate feature
NSUnit only.impl NSCopying for NSUnitElectricResistance
Available on crate feature
NSUnit only.impl NSCopying for NSUnitEnergy
Available on crate feature
NSUnit only.impl NSCopying for NSUnitFrequency
Available on crate feature
NSUnit only.impl NSCopying for NSUnitFuelEfficiency
Available on crate feature
NSUnit only.impl NSCopying for NSUnitIlluminance
Available on crate feature
NSUnit only.impl NSCopying for NSUnitInformationStorage
Available on crate feature
NSUnit only.impl NSCopying for NSUnitLength
Available on crate feature
NSUnit only.impl NSCopying for NSUnitMass
Available on crate feature
NSUnit only.impl NSCopying for NSUnitPower
Available on crate feature
NSUnit only.impl NSCopying for NSUnitPressure
Available on crate feature
NSUnit only.impl NSCopying for NSUnitSpeed
Available on crate feature
NSUnit only.impl NSCopying for NSUnitTemperature
Available on crate feature
NSUnit only.impl NSCopying for NSUnitVolume
Available on crate feature
NSUnit only.impl NSCopying for NSUserNotification
Available on crate feature
NSUserNotification only.impl NSCopying for NSUserNotificationAction
Available on crate feature
NSUserNotification only.impl NSCopying for NSValue
Available on crate feature
NSValue only.impl NSCopying for NSXMLDTD
Available on crate feature
NSXMLDTD only.impl NSCopying for NSXMLDTDNode
Available on crate feature
NSXMLDTDNode only.impl NSCopying for NSXMLDocument
Available on crate feature
NSXMLDocument only.impl NSCopying for NSXMLElement
Available on crate feature
NSXMLElement only.impl NSCopying for NSXMLNode
Available on crate feature
NSXMLNode only.impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying for NSDictionary<KeyType, ObjectType>
Available on crate feature
NSDictionary only.impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying for NSMapTable<KeyType, ObjectType>
Available on crate feature
NSMapTable only.impl<KeyType: ?Sized, ObjectType: ?Sized> NSCopying for NSMutableDictionary<KeyType, ObjectType>
Available on crate feature
NSDictionary only.impl<ObjectType: ?Sized> NSCopying for NSArray<ObjectType>
Available on crate feature
NSArray only.impl<ObjectType: ?Sized> NSCopying for NSHashTable<ObjectType>
Available on crate feature
NSHashTable only.impl<ObjectType: ?Sized> NSCopying for NSMutableArray<ObjectType>
Available on crate feature
NSArray only.impl<ObjectType: ?Sized> NSCopying for NSMutableOrderedSet<ObjectType>
Available on crate feature
NSOrderedSet only.impl<ObjectType: ?Sized> NSCopying for NSMutableSet<ObjectType>
Available on crate feature
NSSet only.impl<ObjectType: ?Sized> NSCopying for NSOrderedSet<ObjectType>
Available on crate feature
NSOrderedSet only.impl<ObjectType: ?Sized> NSCopying for NSSet<ObjectType>
Available on crate feature
NSSet only.impl<UnitType: ?Sized + AsRef<NSUnit>> NSCopying for NSMeasurement<UnitType>
Available on crate feature
NSMeasurement only.