|
38 | 38 | //! let result = pool.get().await; |
39 | 39 | //! assert_eq!(result.unwrap_err().to_string(), "unbounded pool is empty"); |
40 | 40 | //! |
41 | | -//! pool.put(Vec::with_capacity(1024)); |
| 41 | +//! pool.extend_one(Vec::with_capacity(1024)); |
42 | 42 | //! let o = pool.get().await.unwrap(); |
43 | 43 | //! assert_eq!(o.capacity(), 1024); |
44 | 44 | //! drop(o); |
@@ -343,15 +343,49 @@ impl<T, M: ManageObject<Object = T>> Pool<T, M> { |
343 | 343 | Ok(object) |
344 | 344 | } |
345 | 345 |
|
346 | | - /// Put an object to the pool. |
347 | | - pub fn put(&self, o: T) { |
| 346 | + /// Extends the pool with exactly one object. |
| 347 | + /// |
| 348 | + /// # Examples |
| 349 | + /// |
| 350 | + /// ``` |
| 351 | + /// use fastpool::unbounded::Pool; |
| 352 | + /// use fastpool::unbounded::PoolConfig; |
| 353 | + /// |
| 354 | + /// let config = PoolConfig::default(); |
| 355 | + /// let pool = Pool::never_manage(config); |
| 356 | + /// |
| 357 | + /// pool.extend_one(Vec::with_capacity(1024)); |
| 358 | + /// ``` |
| 359 | + pub fn extend_one(&self, o: T) { |
| 360 | + self.extend(Some(o)); |
| 361 | + } |
| 362 | + |
| 363 | + /// Extends the pool with the objects of an iterator. |
| 364 | + /// |
| 365 | + /// # Examples |
| 366 | + /// |
| 367 | + /// ``` |
| 368 | + /// use fastpool::unbounded::Pool; |
| 369 | + /// use fastpool::unbounded::PoolConfig; |
| 370 | + /// |
| 371 | + /// let config = PoolConfig::default(); |
| 372 | + /// let pool = Pool::never_manage(config); |
| 373 | + /// |
| 374 | + /// pool.extend([ |
| 375 | + /// Vec::with_capacity(1024), |
| 376 | + /// Vec::with_capacity(512), |
| 377 | + /// Vec::with_capacity(256), |
| 378 | + /// ]); |
| 379 | + /// ``` |
| 380 | + pub fn extend(&self, iter: impl IntoIterator<Item = T>) { |
348 | 381 | let mut slots = self.slots.lock(); |
349 | | - slots.current_size += 1; |
350 | | - slots.deque.push_back(ObjectState { |
351 | | - o, |
352 | | - status: ObjectStatus::default(), |
353 | | - }); |
354 | | - drop(slots); |
| 382 | + for o in iter { |
| 383 | + slots.current_size += 1; |
| 384 | + slots.deque.push_back(ObjectState { |
| 385 | + o, |
| 386 | + status: ObjectStatus::default(), |
| 387 | + }); |
| 388 | + } |
355 | 389 | } |
356 | 390 |
|
357 | 391 | /// Returns the current status of the pool. |
|
0 commit comments