Skip to content

Commit 6297fb3

Browse files
DarksonnYuryNorov
authored andcommitted
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>
1 parent d0cf651 commit 6297fb3

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

rust/kernel/id_pool.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::bitmap::BitmapVec;
2626
/// use kernel::alloc::{AllocError, flags::GFP_KERNEL};
2727
/// use kernel::id_pool::IdPool;
2828
///
29-
/// let mut pool = IdPool::new(64, GFP_KERNEL)?;
29+
/// let mut pool = IdPool::with_capacity(64, GFP_KERNEL)?;
3030
/// for i in 0..64 {
3131
/// assert_eq!(i, pool.acquire_next_id(i).ok_or(ENOSPC)?);
3232
/// }
@@ -93,13 +93,13 @@ impl ReallocRequest {
9393
}
9494

9595
impl IdPool {
96-
/// Constructs a new [`IdPool`].
96+
/// Constructs a new [`IdPool`] with space for a specific number of bits.
9797
///
9898
/// A capacity below [`MAX_INLINE_LEN`] is adjusted to [`MAX_INLINE_LEN`].
9999
///
100100
/// [`MAX_INLINE_LEN`]: BitmapVec::MAX_INLINE_LEN
101101
#[inline]
102-
pub fn new(num_ids: usize, flags: Flags) -> Result<Self, AllocError> {
102+
pub fn with_capacity(num_ids: usize, flags: Flags) -> Result<Self, AllocError> {
103103
let num_ids = usize::max(num_ids, BitmapVec::MAX_INLINE_LEN);
104104
let map = BitmapVec::new(num_ids, flags)?;
105105
Ok(Self { map })
@@ -129,7 +129,7 @@ impl IdPool {
129129
/// },
130130
/// };
131131
///
132-
/// let mut pool = IdPool::new(1024, GFP_KERNEL)?;
132+
/// let mut pool = IdPool::with_capacity(1024, GFP_KERNEL)?;
133133
/// let alloc_request = pool.shrink_request().ok_or(AllocError)?;
134134
/// let resizer = alloc_request.realloc(GFP_KERNEL)?;
135135
/// pool.shrink(resizer);

0 commit comments

Comments
 (0)