11//! User and Group ID types.
22
3- #![ allow( unsafe_code) ]
4-
53use crate :: backend:: c;
64use crate :: ffi;
75
86/// A group identifier as a raw integer.
9- #[ cfg( not( target_os = "wasi" ) ) ]
107pub type RawGid = ffi:: c_uint ;
118/// A user identifier as a raw integer.
12- #[ cfg( not( target_os = "wasi" ) ) ]
139pub type RawUid = ffi:: c_uint ;
1410
1511/// `uid_t`—A Unix user ID.
@@ -28,11 +24,18 @@ impl Uid {
2824
2925 /// Converts a `RawUid` into a `Uid`.
3026 ///
31- /// # Safety
27+ /// `raw` must be the value of a valid Unix user ID, and not `-1`.
28+ #[ inline]
29+ pub fn from_raw ( raw : RawUid ) -> Self {
30+ debug_assert_ne ! ( raw, -1 as _) ;
31+ Self ( raw)
32+ }
33+
34+ /// Converts a `RawUid` into a `Uid`.
3235 ///
33- /// `raw` must be the value of a valid Unix user ID.
36+ /// `raw` must be the value of a valid Unix user ID, and not `-1` .
3437 #[ inline]
35- pub const unsafe fn from_raw ( raw : RawUid ) -> Self {
38+ pub const fn from_raw_unchecked ( raw : RawUid ) -> Self {
3639 Self ( raw)
3740 }
3841
@@ -55,11 +58,18 @@ impl Gid {
5558
5659 /// Converts a `RawGid` into a `Gid`.
5760 ///
58- /// # Safety
61+ /// `raw` must be the value of a valid Unix group ID, and not `-1`.
62+ #[ inline]
63+ pub fn from_raw ( raw : RawGid ) -> Self {
64+ debug_assert_ne ! ( raw, -1 as _) ;
65+ Self ( raw)
66+ }
67+
68+ /// Converts a `RawGid` into a `Gid`.
5969 ///
60- /// `raw` must be the value of a valid Unix group ID.
70+ /// `raw` must be the value of a valid Unix group ID, and not `-1` .
6171 #[ inline]
62- pub const unsafe fn from_raw ( raw : RawGid ) -> Self {
72+ pub const fn from_raw_unchecked ( raw : RawGid ) -> Self {
6373 Self ( raw)
6474 }
6575
0 commit comments