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 diff --git a/src/sys/resource.rs b/src/sys/resource.rs index 449698dbe2..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,6 +168,7 @@ libc_enum! { /// An alias for RLIMIT_AS. RLIMIT_VMEM, } + impl TryFrom } /// Get the current processes resource limits