Skip to content

Commit 51f1ef3

Browse files
committed
Add infallible conversion from uid_t and gid_t
Implements the following traits: * From<uid_t> for Uid * From<gid_t> for Gid
1 parent b0ab557 commit 51f1ef3

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ This project adheres to [Semantic Versioning](https://semver.org/).
99
- Added `aio_writev` and `aio_readv`.
1010
(#[1713](https://github.com/nix-rust/nix/pull/1713))
1111

12+
- impl `From<uid_t>` for `Uid` and `From<gid_t>` for `Gid`
13+
(#[1727](https://github.com/nix-rust/nix/pull/1727))
1214
- impl From<SockaddrIn> for std::net::SocketAddrV4 and
1315
impl From<SockaddrIn6> for std::net::SocketAddrV6.
1416
(#[1711](https://github.com/nix-rust/nix/pull/1711))

src/unistd.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ impl From<Uid> for uid_t {
8787
}
8888
}
8989

90+
impl From<uid_t> for Uid {
91+
fn from(uid: uid_t) -> Self {
92+
Uid(uid)
93+
}
94+
}
95+
9096
impl fmt::Display for Uid {
9197
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
9298
fmt::Display::fmt(&self.0, f)
@@ -131,6 +137,12 @@ impl From<Gid> for gid_t {
131137
}
132138
}
133139

140+
impl From<gid_t> for Gid {
141+
fn from(gid: gid_t) -> Self {
142+
Gid(gid)
143+
}
144+
}
145+
134146
impl fmt::Display for Gid {
135147
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
136148
fmt::Display::fmt(&self.0, f)

0 commit comments

Comments
 (0)