@@ -22,63 +22,59 @@ pub mod identity {
22
22
pub password : String ,
23
23
}
24
24
25
+ use std:: borrow:: Cow ;
26
+ use std:: path:: Path ;
27
+
28
+ /// Obtain the owner of the given `path`.
29
+ pub fn from_path ( path : Cow < ' _ , Path > ) -> std:: io:: Result < UserId > {
30
+ impl_:: from_path ( path)
31
+ }
32
+
33
+ /// Obtain the of the currently running process.
34
+ pub fn from_process ( ) -> Result < UserId , from_process:: Error > {
35
+ impl_:: from_process ( )
36
+ }
37
+
25
38
///
26
- pub mod user_id {
39
+ pub mod from_process {
40
+ use crate :: identity:: impl_;
41
+
42
+ /// The error returned by [from_process()][super::from_process()].
43
+ pub type Error = impl_:: FromProcessError ;
44
+ }
45
+
46
+ #[ cfg( not( windows) ) ]
47
+ mod impl_ {
27
48
use crate :: identity:: UserId ;
28
49
use std:: borrow:: Cow ;
29
50
use std:: path:: Path ;
30
51
31
- /// Obtain the owner of the given `path`.
32
52
pub fn from_path ( path : Cow < ' _ , Path > ) -> std:: io:: Result < UserId > {
33
- impl_:: from_path ( path)
53
+ use std:: os:: unix:: fs:: MetadataExt ;
54
+ let meta = std:: fs:: symlink_metadata ( path) ?;
55
+ Ok ( meta. uid ( ) )
34
56
}
35
57
36
- /// Obtain the of the currently running process.
37
- pub fn from_process ( ) -> Result < UserId , from_process:: Error > {
38
- impl_:: from_process ( )
58
+ pub type FromProcessError = std:: convert:: Infallible ;
59
+ pub fn from_process ( ) -> Result < UserId , FromProcessError > {
60
+ // SAFETY: there is no documented possibility for failure
61
+ #[ allow( unsafe_code) ]
62
+ let uid = unsafe { libc:: geteuid ( ) } ;
63
+ Ok ( uid)
39
64
}
65
+ }
40
66
41
- ///
42
- pub mod from_process {
43
- use crate :: identity:: user_id:: impl_;
44
-
45
- /// The error returned by [from_process()][super::from_process()].
46
- pub type Error = impl_:: FromProcessError ;
47
- }
48
-
49
- #[ cfg( not( windows) ) ]
50
- mod impl_ {
51
- use crate :: identity:: UserId ;
52
- use std:: borrow:: Cow ;
53
- use std:: path:: Path ;
54
-
55
- pub fn from_path ( path : Cow < ' _ , Path > ) -> std:: io:: Result < UserId > {
56
- use std:: os:: unix:: fs:: MetadataExt ;
57
- let meta = std:: fs:: symlink_metadata ( path) ?;
58
- Ok ( meta. uid ( ) )
59
- }
67
+ #[ cfg( windows) ]
68
+ mod impl_ {
69
+ use crate :: identity:: UserId ;
70
+ use std:: borrow:: Cow ;
71
+ use std:: path:: Path ;
60
72
61
- pub type FromProcessError = std:: convert:: Infallible ;
62
- pub fn from_process ( ) -> Result < UserId , FromProcessError > {
63
- // SAFETY: there is no documented possibility for failure
64
- #[ allow( unsafe_code) ]
65
- let uid = unsafe { libc:: geteuid ( ) } ;
66
- Ok ( uid)
67
- }
73
+ pub fn from_path ( path : Cow < ' _ , Path > ) -> std:: io:: Result < UserId > {
74
+ todo ! ( "unix" )
68
75
}
69
-
70
- #[ cfg( windows) ]
71
- mod impl_ {
72
- use crate :: identity:: UserId ;
73
- use std:: borrow:: Cow ;
74
- use std:: path:: Path ;
75
-
76
- pub fn from_path ( path : Cow < ' _ , Path > ) -> std:: io:: Result < UserId > {
77
- todo ! ( "unix" )
78
- }
79
- pub fn from_process ( ) -> std:: io:: Result < UserId > {
80
- todo ! ( "process" )
81
- }
76
+ pub fn from_process ( ) -> std:: io:: Result < UserId > {
77
+ todo ! ( "process" )
82
78
}
83
79
}
84
80
}
0 commit comments