use objc2::{
encode::{Encode, Encoding, RefEncode},
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObject, NSObjectProtocol, NSString};
use crate::*;
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4BinaryFunctionOptions(pub usize);
bitflags::bitflags! {
impl MTL4BinaryFunctionOptions: usize {
#[doc(alias = "MTL4BinaryFunctionOptionNone")]
const None = 0;
#[doc(alias = "MTL4BinaryFunctionOptionPipelineIndependent")]
const PipelineIndependent = 1<<1;
}
}
unsafe impl Encode for MTL4BinaryFunctionOptions {
const ENCODING: Encoding = usize::ENCODING;
}
unsafe impl RefEncode for MTL4BinaryFunctionOptions {
const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTL4BinaryFunctionDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTL4BinaryFunctionDescriptor {}
);
unsafe impl CopyingHelper for MTL4BinaryFunctionDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTL4BinaryFunctionDescriptor {}
);
impl MTL4BinaryFunctionDescriptor {
extern_methods!(
#[unsafe(method(functionDescriptor))]
#[unsafe(method_family = none)]
pub fn function_descriptor(&self) -> Retained<MTL4FunctionDescriptor>;
#[unsafe(method(setFunctionDescriptor:))]
#[unsafe(method_family = none)]
pub fn set_function_descriptor(
&self,
function_descriptor: &MTL4FunctionDescriptor,
);
#[unsafe(method(options))]
#[unsafe(method_family = none)]
pub fn options(&self) -> MTL4BinaryFunctionOptions;
#[unsafe(method(setOptions:))]
#[unsafe(method_family = none)]
pub fn set_options(
&self,
options: MTL4BinaryFunctionOptions,
);
);
}
impl MTL4BinaryFunctionDescriptor {
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>;
);
}
impl MTL4BinaryFunctionDescriptor {
pub fn name(&self) -> String {
let s: Retained<NSString> = unsafe { msg_send![self, name] };
s.to_string()
}
pub fn set_name(
&self,
name: &str,
) {
unsafe {
let _: () = msg_send![self, setName: &*NSString::from_str(name)];
}
}
}