add util to restore state on scope exit

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-09-29 04:18:47 +00:00 committed by strawberry
parent c9c405facf
commit 16f82b02a0
1 changed files with 9 additions and 3 deletions

View File

@ -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; }};
};
}