From 8514c48110d59b1b8115470267bd7e1c1d6bf9fa Mon Sep 17 00:00:00 2001 From: Jeff Muizelaar Date: Sun, 26 Nov 2017 18:59:47 -0500 Subject: [PATCH] Mark FromVoid more appropriately as unsafe --- core-foundation/src/array.rs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core-foundation/src/array.rs b/core-foundation/src/array.rs index 019ede5..0364363 100644 --- a/core-foundation/src/array.rs +++ b/core-foundation/src/array.rs @@ -23,25 +23,25 @@ use base::{CFIndexConvertible, TCFType, CFRange}; pub struct CFArray(CFArrayRef, PhantomData); /// A trait describing how to convert from the stored *const c_void to the desired T -pub trait FromVoid { - fn from_void(x: *const c_void) -> Self; +pub unsafe trait FromVoid { + unsafe fn from_void(x: *const c_void) -> Self; } -impl FromVoid for u32 { - fn from_void(x: *const c_void) -> u32 { +unsafe impl FromVoid for u32 { + unsafe fn from_void(x: *const c_void) -> u32 { x as usize as u32 } } -impl FromVoid for *const c_void { - fn from_void(x: *const c_void) -> *const c_void { +unsafe impl FromVoid for *const c_void { + unsafe fn from_void(x: *const c_void) -> *const c_void { x } } -impl FromVoid for CFType { - fn from_void(x: *const c_void) -> CFType { - unsafe { TCFType::wrap_under_get_rule(mem::transmute(x)) } +unsafe impl FromVoid for CFType { + unsafe fn from_void(x: *const c_void) -> CFType { + TCFType::wrap_under_get_rule(mem::transmute(x)) } } @@ -121,7 +121,7 @@ impl CFArray { #[inline] pub fn get(&self, index: CFIndex) -> T where T: FromVoid { assert!(index < self.len()); - T::from_void(unsafe { CFArrayGetValueAtIndex(self.0, index) }) + unsafe { T::from_void(CFArrayGetValueAtIndex(self.0, index)) } } pub fn get_values(&self, range: CFRange) -> Vec<*const c_void> {