add util to restore state on scope exit
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
c9c405facf
commit
16f82b02a0
1 changed files with 9 additions and 3 deletions
|
@ -15,8 +15,14 @@ macro_rules! defer {
|
||||||
};
|
};
|
||||||
|
|
||||||
($body:expr) => {
|
($body:expr) => {
|
||||||
$crate::defer! {{
|
$crate::defer! {{ $body }}
|
||||||
$body
|
};
|
||||||
}}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! scope_restore {
|
||||||
|
($val:ident, $ours:expr) => {
|
||||||
|
let theirs = $crate::utils::exchange($val, $ours);
|
||||||
|
$crate::defer! {{ *$val = theirs; }};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue