changeset 7:9380392b9a60

Changes type marker parameter type from Option<T> to PhantomData<T>
author Jesse Hallett <jesse@galois.com>
date Fri, 03 Apr 2015 23:33:20 -0700
parents 2ec97116d72c
children a83c56216e21
files src/conv.rs src/module.rs
diffstat 2 files changed, 5 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/conv.rs	Fri Apr 03 23:16:44 2015 -0700
+++ b/src/conv.rs	Fri Apr 03 23:33:20 2015 -0700
@@ -1,6 +1,7 @@
 use libc::{c_char, c_int};
 use std::{ptr};
 use std::ffi::{CStr, CString};
+use std::marker::{PhantomData};
 
 use constants;
 use constants::*;
@@ -76,5 +77,5 @@
 }
 
 impl PamItem for PamConv {
-    fn item_type(_: Option<Self>) -> PamItemType { PAM_CONV }
+    fn item_type(_: PhantomData<Self>) -> PamItemType { PAM_CONV }
 }
--- a/src/module.rs	Fri Apr 03 23:16:44 2015 -0700
+++ b/src/module.rs	Fri Apr 03 23:33:20 2015 -0700
@@ -3,6 +3,7 @@
 use libc::{c_char};
 use std::{mem, ptr};
 use std::ffi::{CStr, CString};
+use std::marker::{PhantomData};
 
 use constants;
 use constants::*;
@@ -66,10 +67,7 @@
     /// API contract specifies that when the API function `pam_get_item` is
     /// called with the constant PAM_CONV, it will return a value of type
     /// `PamConv`.
-    ///
-    /// The argument will always be `None`.  Its purpose is to provide a type
-    /// label - the value is not important.
-    fn item_type(_: Option<Self>) -> PamItemType;
+    fn item_type(_: PhantomData<Self>) -> PamItemType;
 }
 
 /// Gets some value, identified by `key`, that has been set by the module
@@ -121,7 +119,7 @@
 pub fn get_item<'a, T: PamItem>(pamh: &'a PamHandleT) -> PamResult<&'a T> {
     let mut ptr: *const PamItemT = ptr::null();
     let (res, item) = unsafe {
-        let r = pam_get_item(pamh, PamItem::item_type(None::<T>), &mut ptr);
+        let r = pam_get_item(pamh, PamItem::item_type(PhantomData::<T>), &mut ptr);
         let typed_ptr: *const T = mem::transmute(ptr);
         let t: &T = &*typed_ptr;
         (r, t)