extern_conformance

Macro extern_conformance 

Source
macro_rules! extern_conformance {
    (unsafe impl $(<$($t:ident : $($bound:ident)? $(?$sized:ident)? $(+ $b:path)*),* $(,)?>)? $ty:ident for $protocol:ty {}) => { ... };
}
Expand description

Implement a protocol for an external class.

This creates a given protocol implementation with regards to the type-system. Useful on types created with extern_class!, not use this on custom classes created with define_class!, instead, implement the protocol within that macro.

ยงExamples

use objc2_foundation::NSObjectProtocol;
use objc2::runtime::NSObject;
use objc2::{extern_class, extern_conformance};

extern_class!(
    #[unsafe(super(NSObject))]
    #[derive(PartialEq, Eq, Hash, Debug)]
    pub struct MyClass;
);

// SAFETY: The class `MyClass` conforms to the `NSObject` protocol (since
// its superclass `NSObject` does).
extern_conformance!(unsafe impl NSObjectProtocol for MyClass {});

See the extern_class! macro for more examples.