From 5e4967a3778703de40ef7996ab5173e67b629be6 Mon Sep 17 00:00:00 2001 From: Ben S Date: Tue, 26 Jan 2016 18:57:39 +0000 Subject: [PATCH] Move the traits into their own module --- src/lib.rs | 45 ++------------------------------------------- src/traits.rs | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 43 deletions(-) create mode 100644 src/traits.rs diff --git a/src/lib.rs b/src/lib.rs index 5472f7d..d749d41 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -127,49 +127,8 @@ pub mod mock; pub mod os; pub use os::OSUsers; -/// Trait for producers of users. -pub trait Users { - - /// Returns a User if one exists for the given user ID; otherwise, returns None. - fn get_user_by_uid(&self, uid: uid_t) -> Option>; - - /// Returns a User if one exists for the given username; otherwise, returns None. - fn get_user_by_name(&self, username: &str) -> Option>; - - /// Returns the user ID for the user running the process. - fn get_current_uid(&self) -> uid_t; - - /// Returns the username of the user running the process. - fn get_current_username(&self) -> Option>; - - /// Returns the effective user id. - fn get_effective_uid(&self) -> uid_t; - - /// Returns the effective username. - fn get_effective_username(&self) -> Option>; -} - -/// Trait for producers of groups. -pub trait Groups { - - /// Returns a Group object if one exists for the given group ID; otherwise, returns None. - fn get_group_by_gid(&self, gid: gid_t) -> Option>; - - /// Returns a Group object if one exists for the given groupname; otherwise, returns None. - fn get_group_by_name(&self, group_name: &str) -> Option>; - - /// Returns the group ID for the user running the process. - fn get_current_gid(&self) -> gid_t; - - /// Returns the group name of the user running the process. - fn get_current_groupname(&self) -> Option>; - - /// Returns the effective group id. - fn get_effective_gid(&self) -> gid_t; - - /// Returns the effective group name. - fn get_effective_groupname(&self) -> Option>; -} +mod traits; +pub use traits::{Users, Groups}; #[cfg(any(target_os = "macos", target_os = "freebsd", target_os = "dragonfly"))] #[repr(C)] diff --git a/src/traits.rs b/src/traits.rs new file mode 100644 index 0000000..b4080ba --- /dev/null +++ b/src/traits.rs @@ -0,0 +1,49 @@ +use std::sync::Arc; + +pub use libc::{uid_t, gid_t, c_int}; + +use super::{User, Group}; + +/// Trait for producers of users. +pub trait Users { + + /// Returns a User if one exists for the given user ID; otherwise, returns None. + fn get_user_by_uid(&self, uid: uid_t) -> Option>; + + /// Returns a User if one exists for the given username; otherwise, returns None. + fn get_user_by_name(&self, username: &str) -> Option>; + + /// Returns the user ID for the user running the process. + fn get_current_uid(&self) -> uid_t; + + /// Returns the username of the user running the process. + fn get_current_username(&self) -> Option>; + + /// Returns the effective user id. + fn get_effective_uid(&self) -> uid_t; + + /// Returns the effective username. + fn get_effective_username(&self) -> Option>; +} + +/// Trait for producers of groups. +pub trait Groups { + + /// Returns a Group object if one exists for the given group ID; otherwise, returns None. + fn get_group_by_gid(&self, gid: gid_t) -> Option>; + + /// Returns a Group object if one exists for the given groupname; otherwise, returns None. + fn get_group_by_name(&self, group_name: &str) -> Option>; + + /// Returns the group ID for the user running the process. + fn get_current_gid(&self) -> gid_t; + + /// Returns the group name of the user running the process. + fn get_current_groupname(&self) -> Option>; + + /// Returns the effective group id. + fn get_effective_gid(&self) -> gid_t; + + /// Returns the effective group name. + fn get_effective_groupname(&self) -> Option>; +} \ No newline at end of file