use super::{Device, DeviceNotificationName};
use crate::Error;
pub struct LogHandlerRegistration {
_inner: metal_rust_ffi::LogHandlerRegistration,
}
impl super::LogState {
pub fn add_log_handler(
&self,
handler: impl Fn(String, String, super::LogLevel, String) + Send + Sync + 'static,
) -> Result<LogHandlerRegistration, Error> {
self.inner
.add_log_handler(handler)
.map(|inner| LogHandlerRegistration { _inner: inner })
.map_err(Error::from_ffi)
}
}
pub struct DeviceObserverRegistration {
_inner: metal_rust_ffi::DeviceObserverRegistration,
}
impl Device {
#[must_use]
pub fn all() -> Vec<Self> {
metal_rust_ffi::all_devices()
.into_iter()
.map(Self::from_ffi)
.collect()
}
pub fn all_with_observer(
handler: impl Fn(Device, DeviceNotificationName) + Send + Sync + 'static,
) -> Result<(Vec<Self>, DeviceObserverRegistration), Error> {
metal_rust_ffi::all_devices_with_observer(move |device, name| {
handler(
Device::from_ffi(device),
DeviceNotificationName::from_owned(name),
);
})
.map(|(devices, registration)| {
(
devices.into_iter().map(Self::from_ffi).collect(),
DeviceObserverRegistration {
_inner: registration,
},
)
})
.map_err(Error::from_ffi)
}
}
pub const METAL_CPP_VERSION_MAJOR: u32 = metal_rust_ffi::METAL_CPP_VERSION_MAJOR;
pub const METAL_CPP_VERSION_MINOR: u32 = metal_rust_ffi::METAL_CPP_VERSION_MINOR;
pub const METAL_CPP_VERSION_PATCH: u32 = metal_rust_ffi::METAL_CPP_VERSION_PATCH;
#[must_use]
pub const fn metal_cpp_supports_version(major: u32, minor: u32, patch: u32) -> bool {
metal_rust_ffi::metal_cpp_supports_version(major, minor, patch)
}