fluid-let
fluid-let implements dynamically scoped variables.
Dynamic or fluid variables are a handy way to define global configuration values. They come from the Lisp family of languages where they are relatively popular for this use case.
Usage
Add this to your Cargo.toml:
[]
= "1"
You can declare global dynamic variables using fluid_let!
macro.
Suppose you want to have a configurable Debug
implementation for your hashes,
controlling whether to print out the whole hash or a truncated version:
use fluid_let;
fluid_let!;
Enable full print out using the fluid_set!
macro.
Assignments to dynamic variables are effective for a certain dynamic scope.
In this case, while the function is being executed:
use fluid_set;
And here is how you can implement Debug
that uses dynamic configuration:
Here we print either the full value of the hash, or a truncated version, based on whether debugging mode has been enabled by the caller or not.
License
The code is licensed under MIT license (see LICENSE).