From b047f647b70acaedb282dabf5dd3a28ee90c2060 Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Sun, 11 Oct 2020 16:31:26 +0900 Subject: [PATCH] net: make UCred fields private (#2936) --- tokio/src/net/unix/ucred.rs | 16 ++++++++++++++-- tokio/tests/uds_cred.rs | 4 ++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tokio/src/net/unix/ucred.rs b/tokio/src/net/unix/ucred.rs index 466aedc21..ef214a702 100644 --- a/tokio/src/net/unix/ucred.rs +++ b/tokio/src/net/unix/ucred.rs @@ -4,9 +4,21 @@ use libc::{gid_t, uid_t}; #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)] pub struct UCred { /// UID (user ID) of the process - pub uid: uid_t, + uid: uid_t, /// GID (group ID) of the process - pub gid: gid_t, + gid: gid_t, +} + +impl UCred { + /// Gets UID (user ID) of the process. + pub fn uid(&self) -> uid_t { + self.uid + } + + /// Gets GID (group ID) of the process. + pub fn gid(&self) -> gid_t { + self.gid + } } #[cfg(any(target_os = "linux", target_os = "android"))] diff --git a/tokio/tests/uds_cred.rs b/tokio/tests/uds_cred.rs index c02b2aee4..5bd97fc57 100644 --- a/tokio/tests/uds_cred.rs +++ b/tokio/tests/uds_cred.rs @@ -25,6 +25,6 @@ async fn test_socket_pair() { let uid = unsafe { geteuid() }; let gid = unsafe { getegid() }; - assert_eq!(cred_a.uid, uid); - assert_eq!(cred_a.gid, gid); + assert_eq!(cred_a.uid(), uid); + assert_eq!(cred_a.gid(), gid); }