use std::path::{Path, PathBuf};
use objc2::{
extern_class, extern_conformance, extern_methods, msg_send,
rc::{Allocated, Retained},
runtime::NSObject,
};
use objc2_foundation::{CopyingHelper, NSCopying, NSObjectProtocol, NSURL};
extern_class!(
#[unsafe(super(NSObject))]
#[derive(Debug, PartialEq, Eq, Hash)]
pub struct MTLBinaryArchiveDescriptor;
);
extern_conformance!(
unsafe impl NSCopying for MTLBinaryArchiveDescriptor {}
);
unsafe impl CopyingHelper for MTLBinaryArchiveDescriptor {
type Result = Self;
}
extern_conformance!(
unsafe impl NSObjectProtocol for MTLBinaryArchiveDescriptor {}
);
impl MTLBinaryArchiveDescriptor {
extern_methods!();
pub fn path(&self) -> Option<PathBuf> {
let url: Option<Retained<NSURL>> = unsafe { msg_send![self, url] };
url.and_then(|url| url.to_file_path())
}
pub fn set_path(
&self,
path: Option<&Path>,
) {
let url = path.and_then(NSURL::from_file_path);
unsafe {
let _: () = msg_send![self, setUrl: url.as_deref()];
}
}
}
impl MTLBinaryArchiveDescriptor {
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>;
);
}