@@ -25,15 +25,53 @@ use sys::platform::fs::MetadataExt as UnixMetadataExt;
25
25
pub trait PermissionsExt {
26
26
/// Returns the underlying raw `mode_t` bits that are the standard Unix
27
27
/// permissions for this file.
28
+ ///
29
+ /// # Examples
30
+ ///
31
+ /// ```rust,ignore
32
+ /// use std::fs::File;
33
+ /// use std::os::unix::fs::PermissionsExt;
34
+ ///
35
+ /// let f = try!(File::create("foo.txt"));
36
+ /// let metadata = try!(f.metadata());
37
+ /// let permissions = metadata.permissions();
38
+ ///
39
+ /// println!("permissions: {}", permissions.mode());
40
+ /// ```
28
41
#[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
29
42
fn mode ( & self ) -> u32 ;
30
43
31
44
/// Sets the underlying raw bits for this set of permissions.
45
+ ///
46
+ /// # Examples
47
+ ///
48
+ /// ```rust,ignore
49
+ /// use std::fs::File;
50
+ /// use std::os::unix::fs::PermissionsExt;
51
+ ///
52
+ /// let f = try!(File::create("foo.txt"));
53
+ /// let metadata = try!(f.metadata());
54
+ /// let mut permissions = metadata.permissions();
55
+ ///
56
+ /// permissions.set_mode(0o644); // Read/write for owner and read for others.
57
+ /// assert_eq!(permissions.mode(), 0o644);
58
+ /// ```
32
59
#[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
33
60
fn set_mode ( & mut self , mode : u32 ) ;
34
61
35
62
/// Creates a new instance of `Permissions` from the given set of Unix
36
63
/// permission bits.
64
+ ///
65
+ /// # Examples
66
+ ///
67
+ /// ```rust,ignore
68
+ /// use std::fs::Permissions;
69
+ /// use std::os::unix::fs::PermissionsExt;
70
+ ///
71
+ /// // Read/write for owner and read for others.
72
+ /// let permissions = Permissions::from_mode(0o644);
73
+ /// assert_eq!(permissions.mode(), 0o644);
74
+ /// ```
37
75
#[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
38
76
fn from_mode ( mode : u32 ) -> Self ;
39
77
}
@@ -63,6 +101,18 @@ pub trait OpenOptionsExt {
63
101
/// If no `mode` is set, the default of `0o666` will be used.
64
102
/// The operating system masks out bits with the systems `umask`, to produce
65
103
/// the final permissions.
104
+ ///
105
+ /// # Examples
106
+ ///
107
+ /// ```rust,ignore
108
+ /// extern crate libc;
109
+ /// use std::fs::OpenOptions;
110
+ /// use std::os::unix::fs::OpenOptionsExt;
111
+ ///
112
+ /// let mut options = OpenOptions::new();
113
+ /// options.mode(0o644); // Give read/write for owner and read for others.
114
+ /// let file = options.open("foo.txt");
115
+ /// ```
66
116
#[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
67
117
fn mode ( & mut self , mode : u32 ) -> & mut Self ;
68
118
0 commit comments