mirror of
https://github.com/torvalds/linux.git
synced 2025-12-07 20:06:24 +00:00
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>
This commit is contained in:
committed by
Yury Norov (NVIDIA)
parent
d0cf6512bb
commit
6297fb3863
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user