From 537d6946e4570a9425aa5c881454e67bedf210b0 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 23 Feb 2015 15:26:18 -0800 Subject: [PATCH] std: Expose a `mode` accessor for Permissions on unix Currently we have a `set_mode` mutator, so this just adds the pairing of a `mode` accessor to read the value. Closes #22738 --- src/libstd/fs.rs | 4 ++++ src/libstd/sys/unix/ext.rs | 3 +++ src/libstd/sys/unix/fs2.rs | 1 + 3 files changed, 8 insertions(+) diff --git a/src/libstd/fs.rs b/src/libstd/fs.rs index 98c1b50a9bf..c6ceced4598 100644 --- a/src/libstd/fs.rs +++ b/src/libstd/fs.rs @@ -325,6 +325,10 @@ impl FromInner for Permissions { } } +impl AsInner for Permissions { + fn as_inner(&self) -> &fs_imp::FilePermissions { &self.0 } +} + impl Iterator for ReadDir { type Item = io::Result; diff --git a/src/libstd/sys/unix/ext.rs b/src/libstd/sys/unix/ext.rs index b8b9dcfb3c6..3f9da6e3c51 100644 --- a/src/libstd/sys/unix/ext.rs +++ b/src/libstd/sys/unix/ext.rs @@ -173,10 +173,13 @@ impl OsStrExt for OsStr { // Unix-specific extensions to `Permissions` pub trait PermissionsExt { + fn mode(&self) -> i32; fn set_mode(&mut self, mode: i32); } impl PermissionsExt for Permissions { + fn mode(&self) -> i32 { self.as_inner().mode() } + fn set_mode(&mut self, mode: i32) { *self = FromInner::from_inner(FromInner::from_inner(mode)); } diff --git a/src/libstd/sys/unix/fs2.rs b/src/libstd/sys/unix/fs2.rs index 92a47c6c385..d77e76241cc 100644 --- a/src/libstd/sys/unix/fs2.rs +++ b/src/libstd/sys/unix/fs2.rs @@ -86,6 +86,7 @@ impl FilePermissions { self.mode |= 0o222; } } + pub fn mode(&self) -> i32 { self.mode as i32 } } impl FromInner for FilePermissions {