From d20b8abc9cbb752bc8ef7de3bbc257dda19f91d3 Mon Sep 17 00:00:00 2001 From: ratake <32758555+ratake@users.noreply.github.com> Date: Tue, 7 Nov 2017 20:44:12 -0800 Subject: [PATCH] Implement Eq for all types --- core-foundation-sys/src/base.rs | 1 - core-foundation/src/base.rs | 9 +++++++++ core-foundation/src/lib.rs | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/core-foundation-sys/src/base.rs b/core-foundation-sys/src/base.rs index 03f81ba..71d1ec9 100644 --- a/core-foundation-sys/src/base.rs +++ b/core-foundation-sys/src/base.rs @@ -93,7 +93,6 @@ extern { //fn CFCopyDescription //fn CFCopyTypeIDDescription - //fn CFEqual //fn CFGetAllocator pub fn CFEqual(cf1: CFTypeRef, cf2: CFTypeRef) -> Boolean; pub fn CFGetRetainCount(cf: CFTypeRef) -> CFIndex; diff --git a/core-foundation/src/base.rs b/core-foundation/src/base.rs index 5e55b8b..308761c 100644 --- a/core-foundation/src/base.rs +++ b/core-foundation/src/base.rs @@ -38,6 +38,15 @@ impl Clone for CFType { } } +impl PartialEq for CFType { + #[inline] + fn eq(&self, other: &CFType) -> bool { + unsafe { + CFEqual(self.as_CFTypeRef(), other.as_CFTypeRef()) != 0 + } + } +} + impl Drop for CFType { fn drop(&mut self) { unsafe { diff --git a/core-foundation/src/lib.rs b/core-foundation/src/lib.rs index f4ca71d..0495b7b 100644 --- a/core-foundation/src/lib.rs +++ b/core-foundation/src/lib.rs @@ -45,6 +45,15 @@ macro_rules! impl_TCFType { } } } + + impl PartialEq for $ty { + #[inline] + fn eq(&self, other: &$ty) -> bool { + self.as_CFType().eq(&other.as_CFType()) + } + } + + impl Eq for $ty { } } }