From 64d944780aaa4d2dd261fe679a98bcfd1917bcb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Linus=20F=C3=A4rnstrand?= Date: Wed, 22 Nov 2017 16:27:32 +0100 Subject: [PATCH] Simplify and document CFDictionary::get --- core-foundation/src/dictionary.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/core-foundation/src/dictionary.rs b/core-foundation/src/dictionary.rs index 65276a0..05486e9 100644 --- a/core-foundation/src/dictionary.rs +++ b/core-foundation/src/dictionary.rs @@ -96,13 +96,16 @@ impl CFDictionary { self.find(key.as_concrete_TypeRef() as *const c_void) } + /// # Panics + /// + /// Panics if the key is not present in the dictionary. Use `find` to get an `Option` instead + /// of panicking. #[inline] pub fn get(&self, key: *const c_void) -> *const c_void { - let value = self.find(key); - if value.is_none() { - panic!("No entry found for key {:p}", key); + match self.find(key) { + None => panic!("No entry found for key {:p}", key), + Some(value) => value } - value.unwrap() } /// A convenience function to retrieve `CFType` instances.