diff --git a/src/lib.rs b/src/lib.rs index 8c69eab..3783805 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -107,12 +107,11 @@ pub enum Error { /// Helper module containing enums representing [Subjects](Subject) mod subject { use super::ParseError; - use std::fmt; use nix::unistd::{self, Uid}; + use std::fmt; /// Represents a user subject #[derive(Clone, Debug, PartialEq, Eq, Hash)] - #[cfg_attr(feature = "serialize", derive(serde::Serialize))] pub struct User(pub Uid); impl User { @@ -143,6 +142,16 @@ mod subject { } } + #[cfg(feature = "serialize")] + impl serde::Serialize for User { + fn serialize(&self, serializer: S) -> Result + where + S: serde::Serializer, + { + self.0.as_raw().serialize(serializer) + } + } + impl<'a> From<&'a User> for String { fn from(user: &'a User) -> String { format!("user:{}", user.0)