Function log_mdc::insert_scoped
[−]
[src]
pub fn insert_scoped<K, V>(key: K, value: V) -> InsertGuard where K: Into<String>, V: Into<String>
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));