A policy defining how pooled elements of type
T are reused.
A recycling policy provides two operations:
defines how new elements of type
T are initially constructed, and
Recycle::recycle, which, given an
&mut T, prepares that element for
This trait is intended to allow defining custom policies to reuse values
that are expensive to create or destroy. If a type
T owns a large memory
allocation or other reuseable resource (such as a file descriptor, network
connection, worker thread, et cetera), the
operation can clear any data associated with a particular use of that
value while retaining its memory allocation or other resources. For example,
WithCapacity recycling policy clears standard library collections
Vec in place, retaining their allocated heap
capacity, so that future uses of those collections do not need to
Returns a new instance of type
This method will be called to populate the pool with the initial set of elements. It may also be called if an element is permanently removed from the pool and will not be returned.
element element for reuse.
Typically, this clears any data stored in
element in place, but
retains any previous heap allocations owned by
element so that they
can be used again.
This method is called when a
T value is returned to the pool that owns