Function log_mdc::extend_scoped
source · [−]pub fn extend_scoped<K, V, I>(entries: I) -> ExtendGuard where
K: Into<String>,
V: Into<String>,
I: IntoIterator<Item = (K, V)>,
Expand description
Extends the MDC with new entries in a scoped fashion.
When the returned guard falls out of scope, it will restore the old values corresponding to the keys.
Examples
log_mdc::insert("foo", "a");
let entries = [
("foo", "b"),
("fizz", "buzz"),
];
let guard = log_mdc::extend_scoped(entries.iter().cloned());
log_mdc::get("foo", |v| assert_eq!(Some("b"), v));
log_mdc::get("fizz", |v| assert_eq!(Some("buzz"), v));
drop(guard);
log_mdc::get("foo", |v| assert_eq!(Some("a"), v));
log_mdc::get("fizz", |v| assert_eq!(None, v));