diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-05-01 20:21:18 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-01 20:21:18 +0000 |
commit | bb875f26f2f1e71d32822f65849786ca7101e992 (patch) | |
tree | beb72c20f41176ebc36a37ae49431f7770f5254e /src | |
parent | 0e1bbcf72f9d30cd5a61c9e75f1333baa7e0289e (diff) | |
parent | 8fa391cbc78c68e5646db5bc81546ef571d21a54 (diff) | |
download | nix-bb875f26f2f1e71d32822f65849786ca7101e992.zip |
Merge #1429
1429: constify from_raw and as_raw for Uid, Gid and Pid and Uid::is_root r=asomers a=Blub
Make some integer wrapper methods `const fn`.
* `Uid::from_raw`
* `Uid::as_raw`
* `Uid::is_root`
* `Gid::from_raw`
* `Gid::as_raw`
* `Pid::from_raw`
* `Pid::as_raw`
(Changelog mentions rust 1.40.0 as minimum required version which seems to compile this fine (using 1.40.0 from rustup))
Co-authored-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/unistd.rs | 16 |
1 files changed, 8 insertions, 8 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index d3afeac6..2061341a 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -38,7 +38,7 @@ pub struct Uid(uid_t); impl Uid { /// Creates `Uid` from raw `uid_t`. - pub fn from_raw(uid: uid_t) -> Self { + pub const fn from_raw(uid: uid_t) -> Self { Uid(uid) } @@ -53,12 +53,12 @@ impl Uid { } /// Returns true if the `Uid` represents privileged user - root. (If it equals zero.) - pub fn is_root(self) -> bool { - self == ROOT + pub const fn is_root(self) -> bool { + self.0 == ROOT.0 } /// Get the raw `uid_t` wrapped by `self`. - pub fn as_raw(self) -> uid_t { + pub const fn as_raw(self) -> uid_t { self.0 } } @@ -87,7 +87,7 @@ pub struct Gid(gid_t); impl Gid { /// Creates `Gid` from raw `gid_t`. - pub fn from_raw(gid: gid_t) -> Self { + pub const fn from_raw(gid: gid_t) -> Self { Gid(gid) } @@ -102,7 +102,7 @@ impl Gid { } /// Get the raw `gid_t` wrapped by `self`. - pub fn as_raw(self) -> gid_t { + pub const fn as_raw(self) -> gid_t { self.0 } } @@ -128,7 +128,7 @@ pub struct Pid(pid_t); impl Pid { /// Creates `Pid` from raw `pid_t`. - pub fn from_raw(pid: pid_t) -> Self { + pub const fn from_raw(pid: pid_t) -> Self { Pid(pid) } @@ -143,7 +143,7 @@ impl Pid { } /// Get the raw `pid_t` wrapped by `self`. - pub fn as_raw(self) -> pid_t { + pub const fn as_raw(self) -> pid_t { self.0 } } |