From c6604b4c015c260255fc06a50fafb209f8adddf8 Mon Sep 17 00:00:00 2001 From: Yury Date: Wed, 6 Nov 2024 12:16:58 +0300 Subject: [PATCH] tune cf::DictionaryOf api --- cidre/src/cf/dictionary.rs | 18 +++++++++++++++++- cidre/src/cg/image/source.rs | 11 +++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/cidre/src/cf/dictionary.rs b/cidre/src/cf/dictionary.rs index 1b2396bf..3171b490 100644 --- a/cidre/src/cf/dictionary.rs +++ b/cidre/src/cf/dictionary.rs @@ -379,7 +379,10 @@ extern "C" { } -define_cf_type!(DictionaryMut(Dictionary)); +define_cf_type!( + #[doc(alias = "CFMutableDictionary")] + DictionaryMut(Dictionary) +); impl DictionaryMut { pub fn with_capacity(capacity: usize) -> arc::R { @@ -482,6 +485,19 @@ where } } +impl DictionaryOf { + pub fn value<'a>(&'a self, key: &cf::String) -> Option<&'a cf::Plist> { + let mut result = None; + unsafe { + if CFDictionaryGetValueIfPresent(&self.0, key.as_type_ptr(), &mut result) { + Some(std::mem::transmute(result)) + } else { + None + } + } + } +} + impl std::ops::Deref for DictionaryOf where K: arc::Retain, diff --git a/cidre/src/cg/image/source.rs b/cidre/src/cg/image/source.rs index ac71ea10..d7f8b2a6 100644 --- a/cidre/src/cg/image/source.rs +++ b/cidre/src/cg/image/source.rs @@ -60,7 +60,10 @@ impl Src { #[doc(alias = "CGImageSourceCopyProperties")] #[inline] - pub fn props(&self, options: Option<&cf::Dictionary>) -> Option> { + pub fn props( + &self, + options: Option<&cf::Dictionary>, + ) -> Option>> { unsafe { CGImageSourceCopyProperties(self, options) } } @@ -70,7 +73,7 @@ impl Src { &self, index: usize, options: Option<&cf::Dictionary>, - ) -> Option> { + ) -> Option>> { unsafe { CGImageSourceCopyPropertiesAtIndex(self, index, options) } } @@ -119,13 +122,13 @@ extern "C-unwind" { fn CGImageSourceCopyProperties( isrc: &Src, options: Option<&cf::Dictionary>, - ) -> Option>; + ) -> Option>>; fn CGImageSourceCopyPropertiesAtIndex( isrc: &Src, index: usize, options: Option<&cf::Dictionary>, - ) -> Option>; + ) -> Option>>; fn CGImageSourceCreateImageAtIndex( isrc: &Src,