Skip to main content

copy_all_devices_with_observer

Function copy_all_devices_with_observer 

Source
pub fn copy_all_devices_with_observer<F>(
    handler: F,
) -> (Vec<Device>, DeviceObserver)
where F: Fn(&Device, DeviceNotificationName) + Send + 'static,
Expand description

Copy all devices with an observer for hot-plug notifications (macOS only).

This function returns all available devices and sets up an observer that will be notified when devices are added or removed.

C++ equivalent: NS::Array* MTL::CopyAllDevicesWithObserver(NS::Object**, handler)

§Example

use mtl_gpu::device;

let (devices, observer) = device::copy_all_devices_with_observer(|device, notification| {
    println!("Device event: {:?}", notification);
});

// ... use devices ...

// When done observing:
device::remove_device_observer(observer);