[−][src]Macro vulkayes_core::impl_common_handle_traits
Implements Borrow
, Deref
, PartialEq
, Eq
, Hash
, PartialOrd
and Ord
for a type based on its Borrow
implementation.
This macro is closely tied to the HasHandle
and HasSynchronizedHandle
traits.
There are three variants of this macro:
struct MyType<A> { field_on_self: Target, other_field: A } // Base variant // Deref is optional. If it is not desired, the `<Target>` token is appended to `Borrow` instead. impl_common_handle_traits! { impl [A: Debug] Deref<Target>, Borrow, Eq, Hash, Ord for MyType<A> { target = { field_on_self } // Borrows and Derefs to `Target` by invoking `&self.field_on_self` to_handle { .handle() } // Gets a handle from `Target` by invoking `self.field_on_self.handle()` } } // HasHandle variant // struct MyType<A> { // field_on_self: vk::Image, // other_field: A // } // impl_common_handle_traits! { // impl [A: Debug] HasHandle<Target>, Deref, Borrow, Eq, Hash, Ord for MyType<A> { // target = { field_on_self } // } // } // HasSynchronizedHandle variant // struct MyType<A> { // field_on_self: Vutex<vk::Image>, // other_field: A // } // impl_common_handle_traits! { // impl [A: Debug] HasSynchronizedHandle<Target>, Deref, Borrow, Eq, Hash, Ord for MyType<A> { // target = { field_on_self } // } // }
expands to:
// ... // Base variant // Deref is optional impl<A: Debug> std::ops::Deref for MyType<A> { type Target = Target; fn deref(&self) -> &Self::Target { &self.field_on_self } } impl<A: Debug> std::borrow::Borrow<Target> for MyType<A> { fn borrow(&self) -> &Target { &self.field_on_self } } impl<A: Debug> PartialEq for MyType<A> { fn eq(&self, other: &Self) -> bool { self.field_on_self.handle() == other.field_on_self.handle() } } impl<A: Debug> Eq for MyType<A> {} impl<A: Debug> std::hash::Hash for MyType<A> { fn hash<H: std::hash::Hasher>(&self, state: &mut H) { self.field_on_self.handle().hash(state) } } impl<A: Debug> std::cmp::PartialOrd for MyType<A> { fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> { self.field_on_self.handle().partial_cmp(&other.field_on_self.handle()) } } impl<A: Debug> std::cmp::Ord for MyType<A> { fn cmp(&self, other: &Self) -> std::cmp::Ordering { self.field_on_self.handle().cmp(&other.field_on_self.handle()) } } // HasHandle variant adds to the previous implementations also: // impl<A: Debug> vulkayes_core::util::handle::HasHandle<vk::Image> for MyType<A> {} // While HasSynchronizedHandle adds: // impl<A: Debug> vulkayes_core::util::handle::HasSynchronizedHandle<vk::Image> for MyType<A> {}