@@ -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}
0 commit comments