diff options
| author | Alice Ryhl <aliceryhl@google.com> | 2025-11-25 13:59:39 +0000 |
|---|---|---|
| committer | Yury Norov (NVIDIA) <yury.norov@gmail.com> | 2025-11-26 11:25:35 -0500 |
| commit | 6297fb3863d81b0970fd435476b837739c0ea4e7 (patch) | |
| tree | 9f3da702df6d8951706d92cb57b820559b9546ac | |
| parent | d0cf6512bbcf77afb6102f886fcd7fd48b7ae043 (diff) | |
rust: id_pool: rename IdPool::new() to with_capacity()
We want to change ::new() to take no parameters and produce a pool that
is as large as possible while also being inline because that is the
constructor that Rust Binder actually needs.
However, to avoid complications in examples, we still need the current
constructor. So rename it to with_capacity(), which is the idiomatic
Rust name for this kind constructor.
Reviewed-by: Burak Emir <bqe@google.com>
Signed-off-by: Alice Ryhl <aliceryhl@google.com>
Signed-off-by: Yury Norov (NVIDIA) <yury.norov@gmail.com>
| -rw-r--r-- | rust/kernel/id_pool.rs | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/rust/kernel/id_pool.rs b/rust/kernel/id_pool.rs index 0b1f720a1f7d..7968b6c5566b 100644 --- a/rust/kernel/id_pool.rs +++ b/rust/kernel/id_pool.rs @@ -26,7 +26,7 @@ use crate::bitmap::BitmapVec; /// use kernel::alloc::{AllocError, flags::GFP_KERNEL}; /// use kernel::id_pool::IdPool; /// -/// let mut pool = IdPool::new(64, GFP_KERNEL)?; +/// let mut pool = IdPool::with_capacity(64, GFP_KERNEL)?; /// for i in 0..64 { /// assert_eq!(i, pool.acquire_next_id(i).ok_or(ENOSPC)?); /// } @@ -93,13 +93,13 @@ impl ReallocRequest { } impl IdPool { - /// Constructs a new [`IdPool`]. + /// Constructs a new [`IdPool`] with space for a specific number of bits. /// /// A capacity below [`MAX_INLINE_LEN`] is adjusted to [`MAX_INLINE_LEN`]. /// /// [`MAX_INLINE_LEN`]: BitmapVec::MAX_INLINE_LEN #[inline] - pub fn new(num_ids: usize, flags: Flags) -> Result<Self, AllocError> { + pub fn with_capacity(num_ids: usize, flags: Flags) -> Result<Self, AllocError> { let num_ids = usize::max(num_ids, BitmapVec::MAX_INLINE_LEN); let map = BitmapVec::new(num_ids, flags)?; Ok(Self { map }) @@ -129,7 +129,7 @@ impl IdPool { /// }, /// }; /// - /// let mut pool = IdPool::new(1024, GFP_KERNEL)?; + /// let mut pool = IdPool::with_capacity(1024, GFP_KERNEL)?; /// let alloc_request = pool.shrink_request().ok_or(AllocError)?; /// let resizer = alloc_request.realloc(GFP_KERNEL)?; /// pool.shrink(resizer); |
