From 795153e11058ebfd7670b4b7388fd0950844bb3e Mon Sep 17 00:00:00 2001 From: Shahar Naveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 5 Jul 2025 13:11:22 +0300 Subject: [PATCH 1/3] impl `TryFrom` for `nix::sys::resource::Resource` --- src/sys/resource.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sys/resource.rs b/src/sys/resource.rs index 449698dbe2..ab774b5dac 100644 --- a/src/sys/resource.rs +++ b/src/sys/resource.rs @@ -149,6 +149,7 @@ libc_enum! { /// An alias for RLIMIT_AS. RLIMIT_VMEM, } + impl TryFrom } /// Get the current processes resource limits From b40fc4b426e5e3905f52d0f0a1893f574d1c4917 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 5 Jul 2025 14:04:31 +0300 Subject: [PATCH 2/3] Platform dependent TryFrom --- src/sys/resource.rs | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/sys/resource.rs b/src/sys/resource.rs index ab774b5dac..d0dc449f8b 100644 --- a/src/sys/resource.rs +++ b/src/sys/resource.rs @@ -26,6 +26,25 @@ cfg_if! { } } +cfg_if! { + if #[cfg(any( + all( + target_os = "linux", any(target_env = "gnu", target_env = "uclibc") + ), + target_os = "hurd" + ))] { + type resource_repr_t = u32; + } else if #[cfg(any( + bsd, + target_os = "android", + target_os = "aix", + all(target_os = "linux", not(any(target_env = "gnu", target_env = "uclibc"))), + target_os = "cygwin" + ))] { + type resource_repr_t = i32; + } +} + libc_enum! { /// Types of process resources. /// @@ -149,7 +168,7 @@ libc_enum! { /// An alias for RLIMIT_AS. RLIMIT_VMEM, } - impl TryFrom + impl TryFrom } /// Get the current processes resource limits From 84d1e4508fd7d150c188ac8b97c75ecfdcd35119 Mon Sep 17 00:00:00 2001 From: ShaharNaveh <50263213+ShaharNaveh@users.noreply.github.com> Date: Sat, 5 Jul 2025 14:10:29 +0300 Subject: [PATCH 3/3] Add entry to changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4e320bc824..f6431836c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,12 @@ This project adheres to [Semantic Versioning](https://semver.org/). ## [0.30.1] - 2025-05-04 + +### Added + +- Add `TryFrom` trait implementation between `i32`/`u32` and `Resource` + ([#2645](https://github.com/nix-rust/nix/pull/2645)) + ### Fixed - doc.rs build