macro_rules! instances {
() => { ... };
($(#[$attr:meta])* $vis:vis static $NAME:ident: $t:ty = $e:expr; $($rest:tt)*) => { ... };
($(#[$attr:meta])* $vis:vis static $NAME:ident: $t:ty = $e:expr) => { ... };
}
Expand description
Declares that all static variables within the macro body define unique families of linked objects.
Each .get()
on an included static variable returns a new linked object instance,
with all instances obtained from the same static variable being part of the same family.
§Example
linked::instances!(static TOKEN_CACHE: TokenCache = TokenCache::with_capacity(1000));
fn do_something() {
// `.get()` returns a unique linked instance on every call,
// so you are expected to reuse the instance for efficiency.
let token_cache = TOKEN_CACHE.get();
let token1 = token_cache.get_token();
let token2 = token_cache.get_token();
}
§Dynamic family definition
If you do not know in advance how many object families are necessary and need to define them at runtime, consider using these alternatives: