diff src/module.rs @ 12:30831c70e5c0

Remove PhantomData usage. PhantomData is used through the library to substitute associated constants (to types). However, calling `PamItem::item_type(PhantomData<T>)` can easily be substituted by calling `T::item_type()`, getting rid of the need for PhantomData.
author Marc Brinkmann <git@marcbrinkmann.de>
date Sun, 26 Feb 2017 12:12:36 +0100
parents 74b53b921b23
children cc39d168aeb8
line wrap: on
line diff
--- a/src/module.rs	Sun Feb 26 12:08:11 2017 +0100
+++ b/src/module.rs	Sun Feb 26 12:12:36 2017 +0100
@@ -3,7 +3,6 @@
 use libc::c_char;
 use std::{mem, ptr};
 use std::ffi::{CStr, CString};
-use std::marker::PhantomData;
 
 use constants;
 use constants::*;
@@ -66,7 +65,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`.
-    fn item_type(_: PhantomData<Self>) -> PamItemType;
+    fn item_type() -> PamItemType;
 }
 
 /// Gets some value, identified by `key`, that has been set by the module
@@ -121,7 +120,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(PhantomData::<T>), &mut ptr);
+        let r = pam_get_item(pamh, T::item_type(), &mut ptr);
         let typed_ptr: *const T = mem::transmute(ptr);
         let t: &T = &*typed_ptr;
         (r, t)
@@ -145,7 +144,7 @@
 
     let res = unsafe {
         pam_set_item(pamh,
-                     PamItem::item_type(PhantomData::<P>),
+                     P::item_type(),
 
                      // unwrapping is okay here, as c_item will not be a NULL
                      // pointer