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
|
@ -15,8 +15,14 @@ macro_rules! defer {
|
|||
};
|
||||
|
||||
($body:expr) => {
|
||||
$crate::defer! {{
|
||||
$body
|
||||
}}
|
||||
$crate::defer! {{ $body }}
|
||||
};
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! scope_restore {
|
||||
($val:ident, $ours:expr) => {
|
||||
let theirs = $crate::utils::exchange($val, $ours);
|
||||
$crate::defer! {{ *$val = theirs; }};
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue