@@ -25,15 +25,53 @@ use sys::platform::fs::MetadataExt as UnixMetadataExt;
2525pub trait PermissionsExt {
2626 /// Returns the underlying raw `mode_t` bits that are the standard Unix
2727 /// 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+ /// ```
2841 #[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
2942 fn mode ( & self ) -> u32 ;
3043
3144 /// 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+ /// ```
3259 #[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
3360 fn set_mode ( & mut self , mode : u32 ) ;
3461
3562 /// Creates a new instance of `Permissions` from the given set of Unix
3663 /// 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+ /// ```
3775 #[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
3876 fn from_mode ( mode : u32 ) -> Self ;
3977}
@@ -63,6 +101,18 @@ pub trait OpenOptionsExt {
63101 /// If no `mode` is set, the default of `0o666` will be used.
64102 /// The operating system masks out bits with the systems `umask`, to produce
65103 /// 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+ /// ```
66116 #[ stable( feature = "fs_ext" , since = "1.1.0" ) ]
67117 fn mode ( & mut self , mode : u32 ) -> & mut Self ;
68118
0 commit comments