Expand description
This crates introduces a framework to handle explicit ownership.
Explicit ownership is used for object that needs to be cleaned, but cannot use Drop because
the release operation requires a context. For example, when using the rust types to ensures the
locking order, taking a lock requires knowing what locks are already held at this point, and
uses an explicit object to represent this. If the object needs to take a lock during the
release operation, Drop cannot provide it.
An object that uses explicit ownership uses the Releasable trait. The user must calls the
release method on it before it goes out of scope.
A shared object that used explicit ownership used the OwnedRef/WeakRef/TempRef
containers.
The meaning are the following:
- Object that owns the shared object use
OwnedRef. They are responsible to callreleasebefore dropping the reference. - Object that do not owned the shared object use
WeakRef. This acts as a weak reference to the object. They can convert it to a strong reference using theupgrademethod. The returned value is anOption<TempRef>. TheTempRefallows access to the object. Because this doesn’t repsent ownership, theTempRefmust not be kept, in particular, the user should not do any blocking operation while having aTempRef.
Macros§
- release_
after - Macro that ensure the releasable is released with the given context after the body returns.
- release_
iter_ after - Macro that ensure the iterator of releasables are released with the given context after the body returns.
- release_
on_ error - Macro that ensure the releasable is released with the given context if the body returns an error.
Structs§
- Drop
Guard - Owned
Ref - An owning reference to a shared owned object. Each instance must call
releasebefore being dropped.OwnedRefwill panic on Drop in debug builds if it has not been released. - Release
Guard - A wrapper a round a Releasable object that will check, in test and when assertion are enabled, that the value has been released before being dropped.
- TempRef
- A temporary reference to a shared owned object. This permits access to the shared object, but
will block any thread trying to release the last
OwnedRef. As such, such reference must be released as soon as possible. In particular, one must not do any blocking operation while owning such a refeence. - Temp
RefKey - Wrapper around
TempRefallowing to use it in a Set or as a key of a Map. - WeakRef
- A weak reference to a shared owned object. The
upgrademethod try to build aTempReffrom aWeakRefand will fail if there is noOwnedRefleft. - Weak
RefKey - Wrapper around
WeakRefallowing to use it in a Set or as a key of a Map.
Traits§
- Releasable
- The base trait for explicit ownership. Any
Releasableobject must callreleasebefore being dropped. - Share
- Trait for object that can be shared. This is an equivalent of
Clonefor objects that require to be released.
Functions§
- debug_
assert_ no_ local_ temp_ ref - Assert that no temp ref exist on the current thread. This is used before executing a blocking operation to ensure it will not prevent a OwnedRef release.