Mercurial > crates > nonstick
diff src/items.rs @ 51:9d1160b02d2c
Safety and doc fixes:
- Don't panic when given a string with a null character;
instead return `PAM_CONV_ERR`.
- Improve pattern matching and use ?s where appropriate.
- Format etc.
author | Paul Fisher <paul@pfish.zone> |
---|---|
date | Sat, 03 May 2025 18:41:25 -0400 |
parents | ce47901aab7a |
children |
line wrap: on
line diff
--- a/src/items.rs Wed Apr 16 16:55:59 2025 -0400 +++ b/src/items.rs Sat May 03 18:41:25 2025 -0400 @@ -1,3 +1,5 @@ +use std::ffi::CStr; + #[repr(u32)] pub enum ItemType { /// The service name @@ -36,11 +38,11 @@ /// The `ItemType` for this type fn type_id() -> ItemType; - /// The function to convert from the pointer to the C-representation to this safer wrapper type + /// The function to convert from the pointer to the C-representation to this safer wrapper type. /// /// # Safety /// - /// This function can assume the pointer is a valid pointer to a `Self::Raw` instance. + /// This function assumes the pointer is a valid pointer to a `Self::Raw` instance. unsafe fn from_raw(raw: *const Self::Raw) -> Self; /// The function to convert from this wrapper type to a C-compatible pointer. @@ -49,11 +51,12 @@ macro_rules! cstr_item { ($name:ident) => { + ///A `CStr`-based item from a PAM conversation. #[derive(Debug)] - pub struct $name<'s>(pub &'s std::ffi::CStr); + pub struct $name<'s>(pub &'s CStr); impl<'s> std::ops::Deref for $name<'s> { - type Target = &'s std::ffi::CStr; + type Target = &'s CStr; fn deref(&self) -> &Self::Target { &self.0 }