Debian Codegraph @

third_party/rust/wgpu-hal/src/auxil/dxgi/name.rs

raw
1 use windows::Win32::Graphics::Direct3D12::ID3D12Object;
2
3 use crate::auxil::dxgi::result::HResult;
4
5 /// Helper trait for setting the name of a D3D12 object.
6 ///
7 /// This is implemented on all types that can be converted to an [`ID3D12Object`].
8 pub trait ObjectExt {
9 fn set_name(&self, name: &str) -> Result<(), crate::DeviceError>;
10 }
11
12 impl<T> ObjectExt for T
13 where
14 // Windows impls `From` for all parent interfaces, so we can use that to convert to ID3D12Object.
15 //
16 // This includes implementations for references.
17 for<'a> &'a ID3D12Object: From<&'a T>,
18 {
19 fn set_name(&self, name: &str) -> Result<(), crate::DeviceError> {
20 let name = windows::core::HSTRING::from(name);
21 let object: &ID3D12Object = self.into();
22 unsafe { object.SetName(&name).into_device_result("SetName") }
23 }
24 }