feat: nix_util::context::check_call!(func[...])
> I couldn't figure out a way to use () for the function call, but I didn't try that hard. I (Robert) have also given it a shot, briefly, unsuccessfully. While I was critical of over-engineering this, it turns out that when we start to use `mut`, a macro is much more practical, because it doesn't create a new scope where we need a copy of a mutable reference, which of course is not allowed. (cherry picked from commit a2acc93d13991da4b14a99065acd589477334d07)
This commit is contained in:
parent
2f3a5fb039
commit
226639939f
1 changed files with 18 additions and 0 deletions
|
|
@ -96,6 +96,24 @@ impl Drop for Context {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[macro_export]
|
||||||
|
macro_rules! check_call {
|
||||||
|
($f:path[$ctx:expr $(, $arg:expr)*]) => {
|
||||||
|
{
|
||||||
|
let ret = $f($ctx.ptr() $(, $arg)*);
|
||||||
|
match $ctx.check_err() {
|
||||||
|
Ok(_) => Ok(ret),
|
||||||
|
Err(e) => {
|
||||||
|
$ctx.clear();
|
||||||
|
Err(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub use check_call;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue