Skip to content

Commit

Permalink
tune cf::DictionaryOf<cf::String, cf::Plist> api
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 6, 2024
1 parent 9b47810 commit c6604b4
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
18 changes: 17 additions & 1 deletion cidre/src/cf/dictionary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self> {
Expand Down Expand Up @@ -482,6 +485,19 @@ where
}
}

impl DictionaryOf<cf::String, cf::Plist> {
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<K, V> std::ops::Deref for DictionaryOf<K, V>
where
K: arc::Retain,
Expand Down
11 changes: 7 additions & 4 deletions cidre/src/cg/image/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ impl Src {

#[doc(alias = "CGImageSourceCopyProperties")]
#[inline]
pub fn props(&self, options: Option<&cf::Dictionary>) -> Option<arc::R<cf::Dictionary>> {
pub fn props(
&self,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::DictionaryOf<cf::String, cf::Plist>>> {
unsafe { CGImageSourceCopyProperties(self, options) }
}

Expand All @@ -70,7 +73,7 @@ impl Src {
&self,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::Dictionary>> {
) -> Option<arc::R<cf::DictionaryOf<cf::String, cf::Plist>>> {
unsafe { CGImageSourceCopyPropertiesAtIndex(self, index, options) }
}

Expand Down Expand Up @@ -119,13 +122,13 @@ extern "C-unwind" {
fn CGImageSourceCopyProperties(
isrc: &Src,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::Dictionary>>;
) -> Option<arc::R<cf::DictionaryOf<cf::String, cf::Plist>>>;

fn CGImageSourceCopyPropertiesAtIndex(
isrc: &Src,
index: usize,
options: Option<&cf::Dictionary>,
) -> Option<arc::R<cf::Dictionary>>;
) -> Option<arc::R<cf::DictionaryOf<cf::String, cf::Plist>>>;

fn CGImageSourceCreateImageAtIndex(
isrc: &Src,
Expand Down

0 comments on commit c6604b4

Please sign in to comment.