-
Notifications
You must be signed in to change notification settings - Fork 233
Reference type as associated value instead of generic #132
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
249300d
3aa63aa
aae7c70
70dd9c3
c071ba7
ab08525
7e87a9d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ use string::CFStringRef; | |
#[repr(C)] | ||
pub struct __CFError(c_void); | ||
|
||
pub type CFErrorRef = *mut __CFError; | ||
pub type CFErrorRef = *const __CFError; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure if this was |
||
|
||
extern "C" { | ||
pub fn CFErrorGetTypeID() -> CFTypeID; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,7 +81,7 @@ impl_CFTypeDescriptionGeneric!(CFArray); | |
|
||
impl<T> CFArray<T> { | ||
/// Creates a new `CFArray` with the given elements, which must be `CFType` objects. | ||
pub fn from_CFTypes<R>(elems: &[T]) -> CFArray<T> where T: TCFType<R> { | ||
pub fn from_CFTypes(elems: &[T]) -> CFArray<T> where T: TCFType { | ||
unsafe { | ||
let elems: Vec<CFTypeRef> = elems.iter().map(|elem| elem.as_CFTypeRef()).collect(); | ||
let array_ref = CFArrayCreate(kCFAllocatorDefault, | ||
|
@@ -92,13 +92,18 @@ impl<T> CFArray<T> { | |
} | ||
} | ||
|
||
#[deprecated(note = "please use `as_untyped` instead")] | ||
pub fn to_untyped(self) -> CFArray { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I realize now that my previous move to deprecate Do you think I should change the name of the method that will be present in the pub fn to_untyped(&self) -> CFArray { ... } In line with all the new pub fn into_untyped(self) -> CFArray { ... } There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Those seem like worthwhile changes. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Check. I'll add a commit for that. I'll push it after my other PR is merged, as this one will need rebasing/manual conflict resolution after that one anyway. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
#[inline] | ||
pub fn to_untyped(&self) -> CFArray { | ||
unsafe { CFArray::wrap_under_get_rule(self.0) } | ||
} | ||
|
||
pub fn as_untyped(&self) -> CFArray { | ||
unsafe { CFArray::wrap_under_get_rule(self.0) } | ||
/// Returns the same array, but with the type reset to void pointers. | ||
/// Equal to `to_untyped`, but is faster since it does not increment the retain count. | ||
#[inline] | ||
pub fn into_untyped(self) -> CFArray { | ||
let reference = self.0; | ||
mem::forget(self); | ||
unsafe { CFArray::wrap_under_create_rule(reference) } | ||
} | ||
|
||
/// Iterates over the elements of this `CFArray`. | ||
|
@@ -164,19 +169,23 @@ mod tests { | |
assert_eq!(array.retain_count(), 1); | ||
|
||
let untyped_array = array.to_untyped(); | ||
assert_eq!(array.retain_count(), 2); | ||
assert_eq!(untyped_array.retain_count(), 2); | ||
|
||
mem::drop(array); | ||
assert_eq!(untyped_array.retain_count(), 1); | ||
} | ||
|
||
#[test] | ||
fn as_untyped_correct_retain_count() { | ||
fn into_untyped() { | ||
let array = CFArray::<CFType>::from_CFTypes(&[]); | ||
assert_eq!(array.retain_count(), 1); | ||
|
||
let untyped_array = array.as_untyped(); | ||
let array2 = array.to_untyped(); | ||
assert_eq!(array.retain_count(), 2); | ||
|
||
let untyped_array = array.into_untyped(); | ||
assert_eq!(untyped_array.retain_count(), 2); | ||
|
||
mem::drop(array); | ||
mem::drop(array2); | ||
assert_eq!(untyped_array.retain_count(), 1); | ||
} | ||
|
||
|
@@ -215,14 +224,14 @@ mod tests { | |
assert_eq!(iter.len(), 5); | ||
|
||
for elem in iter { | ||
let number: CFNumber = elem.downcast::<_, CFNumber>().unwrap(); | ||
let number: CFNumber = elem.downcast::<CFNumber>().unwrap(); | ||
sum += number.to_i64().unwrap() | ||
} | ||
|
||
assert!(sum == 15); | ||
|
||
for elem in arr.iter() { | ||
let number: CFNumber = elem.downcast::<_, CFNumber>().unwrap(); | ||
let number: CFNumber = elem.downcast::<CFNumber>().unwrap(); | ||
sum += number.to_i64().unwrap() | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this commit should be reordered to come before 3688803.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm. With "this commit" I assume you mean 0fc6b62 ? If so, it does come before 3688803