pub fn insert_scoped<K, V>(key: K, value: V) -> InsertGuardExpand description
Inserts a new entry into the MDC in a scoped fashion.
When the returned guard falls out of scope, it will restore the old value corresponding to the key.
ยงExamples
let guard = log_mdc::insert_scoped("foo", "a");
log_mdc::get("foo", |v| assert_eq!(Some("a"), v));
drop(guard);
log_mdc::get("foo", |v| assert_eq!(None, v));log_mdc::insert("foo", "a");
let guard = log_mdc::insert_scoped("foo", "b");
log_mdc::get("foo", |v| assert_eq!(Some("b"), v));
drop(guard);
log_mdc::get("foo", |v| assert_eq!(Some("a"), v));