dyn-context
This crate provides simple mechanism for safely erasing of 1) lifetimes, 2) generics, and 3) function arguments.
-
Erasing lifetimes.
In Rust, lifetimes are intrusive, and sometimes it can lead to an inadequately complex code. Moreover, in some cases it can lead to an impossible code, means code so complex, so it can not make to compiles, even it is logically meaningful. (Such situations could occur because Rust does not support existential types with infinite parameters list.)
The crate provides a way to "compress" several lifetimed references into a one reference to a
'static
type. This mechanism guarantees type-safety. -
Erasing generics.
There are many reasons, why generics could be not a best choice in some concrete situation. This library provides
State
trait, which may be helpful in such cases. -
Erasing function parameters.
Although this should only be done as a last resort, it can be useful to pass state through thread-local static storage.
Combining all mechanics (lifetimes compression and dynamic context trait passing through thread-local storage) allows building complex systems with callbacks:
use CallBack;
use App;
use free_lifetimes;
use SelfState;
free_lifetimes!