use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::ProtocolObject,
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObject, NSObjectProtocol, NSString};
use crate::*;
extern_class!(
#[unsafe(super(MTL4FunctionDescriptor, NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTL4LibraryFunctionDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTL4LibraryFunctionDescriptor {}
);
unsafe impl CopyingHelper for MTL4LibraryFunctionDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTL4LibraryFunctionDescriptor {}
);
impl MTL4LibraryFunctionDescriptor {
extern_methods!(
#[unsafe(method(library))]
#[unsafe(method_family = none)]
pub fn library(&self) -> Option<Retained<ProtocolObject<dyn MTLLibrary>>>;
#[unsafe(method(setLibrary:))]
#[unsafe(method_family = none)]
pub fn set_library(
&self,
library: Option<&ProtocolObject<dyn MTLLibrary>>,
);
);
pub fn name(&self) -> Option<String> {
let name: Option<Retained<NSString>> = unsafe { msg_send![self, name] };
name.map(|value| value.to_string())
}
pub fn set_name(
&self,
name: Option<&str>,
) {
unsafe {
let _: () = msg_send![self, setName: name.map(NSString::from_str).as_deref()];
}
}
}
impl MTL4LibraryFunctionDescriptor {
extern_methods!(
#[unsafe(method(init))]
#[unsafe(method_family = init)]
pub fn init(this: Allocated<Self>) -> Retained<Self>;
#[unsafe(method(new))]
#[unsafe(method_family = new)]
pub fn new() -> Retained<Self>;
);
}