1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//! rlimit - A simple wrapper for `getrlimit` and `setrlimit`. //! //! # Examples //! //! ## Set resource limit //! ```no_run //! # #[cfg(unix)] //! # { //! use rlimit::{setrlimit, Resource}; //! //! const DEFAULT_SOFT_LIMIT: u64 = 4 * 1024 * 1024; //! const DEFAULT_HARD_LIMIT: u64 = 8 * 1024 * 1024; //! assert!(Resource::FSIZE.set(DEFAULT_SOFT_LIMIT, DEFAULT_HARD_LIMIT).is_ok()); //! //! let soft = 16384; //! let hard = soft * 2; //! assert!(setrlimit(Resource::NOFILE, soft, hard).is_ok()); //! # } //! ``` //! //! ## Get resource limit //! ```no_run //! # #[cfg(unix)] //! # { //! use rlimit::{getrlimit, Resource}; //! //! assert!(Resource::NOFILE.get().is_ok()); //! assert_eq!(getrlimit(Resource::CPU).unwrap(), (rlimit::INFINITY, rlimit::INFINITY)); //! # } //! ``` //! //! ## Increase NOFILE limit //! See the example [nofile](https://github.com/Nugine/rlimit/tree/v0.6.0/examples/nofile.rs). //! //! # Troubleshoot //! //! ## Failed to increase NOFILE to hard limit on macOS //! On macOS, getrlimit by default reports that the hard limit is //! unlimited, but there is usually a stricter hard limit discoverable //! via sysctl (`kern.maxfilesperproc`). Failing to discover this secret stricter hard limit will //! cause the call to setrlimit to fail. //! #![deny( missing_docs, missing_debug_implementations, clippy::all, clippy::pedantic, clippy::nursery, clippy::cargo )] #[allow(unused_macros)] macro_rules! group { ($($tt:tt)*) => { $($tt)* } } #[cfg(unix)] group! { mod unix; #[doc(inline)] pub use self::unix::*; }