Skip to content

Commit

Permalink
Fix the serde feature after fubarnetes#51
Browse files Browse the repository at this point in the history
We should really add a CI configuration that includes that feature.
  • Loading branch information
asomers committed Sep 29, 2024
1 parent fa9abb4 commit ee1822d
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -143,6 +142,16 @@ mod subject {
}
}

#[cfg(feature = "serialize")]
impl serde::Serialize for User {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
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)
Expand Down

0 comments on commit ee1822d

Please sign in to comment.