mtl-rs 0.1.10

Rust bindings for Apple's Metal API
use objc2::{
    encode::{Encode, Encoding, RefEncode},
    extern_protocol,
    rc::Retained,
    runtime::ProtocolObject,
};
use objc2_foundation::{NSInteger, NSObjectProtocol};

use crate::*;

/// Represents the status of a compiler task.
///
/// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4compilertaskstatus?language=objc)
// NS_ENUM
#[repr(transparent)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct MTL4CompilerTaskStatus(pub NSInteger);
impl MTL4CompilerTaskStatus {
    /// No status.
    #[doc(alias = "MTL4CompilerTaskStatusNone")]
    pub const NONE: Self = Self(0);
    /// The compiler task is currently scheduled.
    #[doc(alias = "MTL4CompilerTaskStatusScheduled")]
    pub const SCHEDULED: Self = Self(1);
    /// The compiler task is currently compiling.
    #[doc(alias = "MTL4CompilerTaskStatusCompiling")]
    pub const COMPILING: Self = Self(2);
    /// The compiler task is finished.
    #[doc(alias = "MTL4CompilerTaskStatusFinished")]
    pub const FINISHED: Self = Self(3);
}

unsafe impl Encode for MTL4CompilerTaskStatus {
    const ENCODING: Encoding = NSInteger::ENCODING;
}

unsafe impl RefEncode for MTL4CompilerTaskStatus {
    const ENCODING_REF: Encoding = Encoding::Pointer(&Self::ENCODING);
}

extern_protocol!(
    /// A reference to an asynchronous compilation task that you initiate from a compiler instance.
    ///
    /// See also [Apple's documentation](https://developer.apple.com/documentation/metal/mtl4compilertask?language=objc)
    pub unsafe trait MTL4CompilerTask: NSObjectProtocol {
        /// Returns the compiler instance that this asynchronous compiler task belongs to.
        #[unsafe(method(compiler))]
        #[unsafe(method_family = none)]
        fn compiler(&self) -> Retained<ProtocolObject<dyn MTL4Compiler>>;

        /// Returns the compiler task status.
        ///
        /// The default is `MTL4CompilerStatusNone`.
        #[unsafe(method(status))]
        #[unsafe(method_family = none)]
        fn status(&self) -> MTL4CompilerTaskStatus;

        /// Waits synchronously for this compile task to complete by blocking the calling thread.
        #[unsafe(method(waitUntilCompleted))]
        #[unsafe(method_family = none)]
        fn wait_until_completed(&self);
    }
);