-
-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unify Guard
and PoolGuard
types
#30
Comments
Since we're not actually returning the Lines 15 to 19 in ffa5c7a
This should have equivalent behavior to the current implementation. I think it should be fine to have one code path that's used by both guards. It's only Slab::take that requires special-casing.
|
@bIgBV Are you interested in working on this? I'd like this to be addressed before we publish a release with the object pool API. If you're busy, I'm happy to take care of it so we can move closer to a release. |
@hawkw yeah I'd like to work on this. And the |
Okay, great. I think this is the last release blocker for the pool. |
Looks like this probably isn't going to be possible with the current state of things (see #33 (comment) and #33 (comment)) so I'm not going to block the release on it. |
Currently
Slab::get
returns theGuard
type whilePool::get
returns aPoolGuard
. But looking at the contents of these two types, we can see that they carry the same information. It would be a great win for users if we are able to unify these types.The reason for the difference for the two types comes to their
Drop
implementations:Drop
impl forGuard
sharded-slab/src/lib.rs
Lines 499 to 511 in ffa5c7a
PoolGuard
sharded-slab/src/pool/mod.rs
Lines 232 to 249 in ffa5c7a
Both these impls, while calling different methods, are calling the "mark for release" chain. The final guard being dropped is responsible for actually clearing the storage. The calls eventually lead to
Slot::try_remove_value
forGuard
s drop impl andSlot::try_clear_storage
forPoolGuard
s drop impl. The sole difference comes down to themutator
parameter being passed to therelease_with
method for theSlab
andPool
impls.The mutator closure in
Pool
s case calls theClear::clear
onT
, therefore we need theT: Clear
bound to be true. In theSlab
s case we need the type to be anOption<T>
in order to callOption::take
.If we can find a way to scoping those two pieces of functionality to impl block bounded by the specific generic types we will be able to expose a unified guard type. Not only that but we will be able to share a lot more code throughout the crate as a lot of the functions in this particular code path are repetitive.
The text was updated successfully, but these errors were encountered: